Re: [racket-users] Re: How do I get (system-tzid) to return the correct value?

2019-02-21 Thread Jon Zeppieri
I just realized that some of my instructions rely on DrRacket, and you
mentioned that this is on AWS, so you probably you're likely not running
that. The reason I suggested running the code in DrRacket is that it allows
you to work within a module, so that you're not restricted to calling only
provided functions. But you can do the same in the textual repl, I think,
using `enter!`.

- Jon

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: How do I get (system-tzid) to return the correct value?

2019-02-21 Thread Jon Zeppieri
On Thu, Feb 21, 2019 at 10:12 PM Brian Adkins  wrote:

> On Thursday, February 21, 2019 at 9:54:23 PM UTC-5, Jon Zeppieri wrote:
>>
>>
>>
>> On Thu, Feb 21, 2019 at 9:48 PM Brian Adkins  wrote:
>>
>>> On Thursday, February 21, 2019 at 9:35:58 PM UTC-5, Brian Adkins wrote:

 On Thursday, February 21, 2019 at 9:26:07 PM UTC-5, Brian Adkins wrote:
>
> I'm using the (today) function from the gregor library. It was
> returning tomorrow instead of today, so I thought the problem was the
> timezone on my Ubuntu server. I configured the timezone to be US/Eastern
> via: sudo dpkg-reconfigure tzdata
>
> Now the date command returns:  Thu Feb 21 21:23:43 EST 2019   as
> expected.
>
> Unfortunately, (system-tzid) returns:  "Etc/UTC"
>
> So, gregor's (today) still returns tomorrow (since it's so late).
>
> Anyone know how to get (system-tzid) to return the correct value on
> Ubuntu?
>

 Some more info:

 /etc/localtime is linked as:  localtime ->
 /usr/share/zoneinfo/US/Eastern

>>>
>>> I reinvoked sudo dpkg-reconfigure tzdata  and chose America/New_York
>>> instead of  US/Eastern, but I still get the default "Etc/UTC" from
>>> (system-tzid)
>>>
>>
>>
>> Huh. Could you do the following and tell me what you get?
>>
>> > (require tzinfo/private/generics)
>> > (require tzinfo/private/zoneinfo)
>> > (define zi (make-zoneinfo-source))
>> > (zoneinfo-dir zi)
>> "/usr/share/zoneinfo"
>> > (detect-system-tzid zi)
>> "America/New_York"
>>
>
> > (require tzinfo/private/generics)
> > (require tzinfo/private/zoneinfo)
> > (define zi (make-zoneinfo-source))
> > (zoneinfo-dir zi)
> "/usr/share/zoneinfo"
> > (detect-system-tzid zi)
> #f
>
> Also:
>
> $ ls -l /etc/localtime
> lrwxrwxrwx 1 root root 36 Feb 21 21:45 /etc/localtime ->
> /usr/share/zoneinfo/America/New_York
>
> $ cat /etc/timezone
> America/New_York
>
>

Thanks.

Okay, so first I figured that the problem was probably due to the weird way
that I try to discover the target of an /etc/timezone symlink. (Racket
doesn't provide that functionality, as far as I could tell at the time, and
I guess I wanted to avoid the FFI? Even though I used it for Windows? My
memory fails me.)

But, if that method fails, it also tries getting the value from
/etc/timezone, which you noted, is set correctly. And that method of
getting the timezone is really simple. It just reads the file. So... hmm.
Okay, let's do this exhaustively.

1. Verify that (system-type) is 'unix. (Just to make sure we check
everything.)

2. In DrRacket, in the definitions window, put the following:
```
#lang racket/base

(require tzinfo/private/zoneinfo)
```
3. Right click on `tzinfo/private/zoneinfo` and select "Open zoneinfo.rkt."

4. In the new DrRacket window that contains the source of zoneinfo.rkt,
click "Run."

5. Then, in the interaction pane, do:
> (define zi (make-zoneinfo-source))
> (tzinfo-has-tzid? zi "America/New_York")
#t

If this is #f, that would be bad, and you can stop right there.

6. Next:
> (find-zoneinfo-directory default-zoneinfo-search-path)
"/usr/share/zoneinfo"

If you don't get the same values for this, that would be odd.

7.
> (detect-tzid/unix (zoneinfo-dir zi)
(find-zoneinfo-directory default-zoneinfo-search-path)
(tzinfo->all-tzids zi))
"America/New_York"

I expect you'll either get #f here or else you'll get a string but it won't
be a valid IANA time zone name.

8. Near the top of zoneinfo.rkt, you'll see a require line for
"os/unix.rkt." Right click that and open the file. Run it.

9. In the interactions pane:
> (tzid-from-env)
#f

(If this isn't #f, and it also isn't an valid IANA time zone id, that would
be the problem.)

10.
> (tzid-from-/etc/timezone)
#f

Based on what you wrote above, I expect you to get "America/New_York" here.
(I get #f, but I'm on OS X.)

===

I think you'll have to get unexpected results from one of these, and that
should help us figure out the problem.
My best guess right now is that detect-tzid/unix will return a string that
isn't a valid IANA tzid. And that might be because you have the TZ
environment variable set.

Thank you for helping me track down this bug. If my guess is correct, I
need to make a slight change to the code.

(Summary: detect-tzid/unix tries a few different methods for determining
the system time zone, and it stops when any one of them is non-#f. But the
returned string is only validated against the list of IANA zones
afterwards, so if any of those methods returns a string that isn't a valid
time zone, it won't try any of the other methods.)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Help with generators from python land!

2019-02-21 Thread Konrad Hinsen

On 21/02/2019 20:40, Zelphir Kaltstahl wrote:
Python, I believe, has some kind of `Iterable` interface, which a 
generator satisfies and which specifies the method to call to get the 
next value. In Racket maybe one would have to do with a convention of 
how to get a next value from a lazy list.


Python's concept of iterables is very similar to Racket's streams 
(https://docs.racket-lang.org/reference/streams.html) and sequences 
(https://docs.racket-lang.org/reference/sequences.html). And Python 
generators are very similar to Racket generators 
(https://docs.racket-lang.org/reference/Generators.html). The main 
difference, as has been pointed out before, is that Python generators 
are more common as an idiom for solving problems that in Racket would 
typically be approached differently.


Konrad.


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: How do I get (system-tzid) to return the correct value?

2019-02-21 Thread Brian Adkins


On Thursday, February 21, 2019 at 10:12:02 PM UTC-5, Brian Adkins wrote:
>
> On Thursday, February 21, 2019 at 9:54:23 PM UTC-5, Jon Zeppieri wrote:
>>
>>
>>
>> On Thu, Feb 21, 2019 at 9:48 PM Brian Adkins  wrote:
>>
>>> On Thursday, February 21, 2019 at 9:35:58 PM UTC-5, Brian Adkins wrote:

 On Thursday, February 21, 2019 at 9:26:07 PM UTC-5, Brian Adkins wrote:
>
> I'm using the (today) function from the gregor library. It was 
> returning tomorrow instead of today, so I thought the problem was the 
> timezone on my Ubuntu server. I configured the timezone to be US/Eastern 
> via: sudo dpkg-reconfigure tzdata
>
> Now the date command returns:  Thu Feb 21 21:23:43 EST 2019   as 
> expected.
>
> Unfortunately, (system-tzid) returns:  "Etc/UTC"
>
> So, gregor's (today) still returns tomorrow (since it's so late).
>
> Anyone know how to get (system-tzid) to return the correct value on 
> Ubuntu?
>

 Some more info:

 /etc/localtime is linked as:  localtime -> 
 /usr/share/zoneinfo/US/Eastern 

>>>
>>> I reinvoked sudo dpkg-reconfigure tzdata  and chose America/New_York  
>>> instead of  US/Eastern, but I still get the default "Etc/UTC" from 
>>> (system-tzid) 
>>>
>>
>>
>> Huh. Could you do the following and tell me what you get?
>>
>> > (require tzinfo/private/generics)
>> > (require tzinfo/private/zoneinfo)
>> > (define zi (make-zoneinfo-source))
>> > (zoneinfo-dir zi)
>> "/usr/share/zoneinfo"
>> > (detect-system-tzid zi)
>> "America/New_York"
>>
>
> > (require tzinfo/private/generics)
> > (require tzinfo/private/zoneinfo)
> > (define zi (make-zoneinfo-source))
> > (zoneinfo-dir zi)
> "/usr/share/zoneinfo"
> > (detect-system-tzid zi)
> #f
>
> Also:
>
> $ ls -l /etc/localtime
> lrwxrwxrwx 1 root root 36 Feb 21 21:45 /etc/localtime -> 
> /usr/share/zoneinfo/America/New_York
>
> $ cat /etc/timezone
> America/New_York
>  
>
>>  
>>
>
I gotta hit the sack, but a couple more pieces of info:

Racket v7.1
Ubuntu 18.04 running on Amazon EC2

$ raco pkg show
Installation-wide:
 PackageChecksum Source
 main-distribution  107e1b59943f693b...  catalog...tribution
 racket-lib 21fbc2a1a2972f1f...  catalog racket-lib
 [194 auto-installed packages not shown]
User-specific for installation "7.1":
 PackageChecksumSource
 gregor 3b4acc9b41806091b0f...  catalog...?path=gregor
 libuuid4bead1a3ccfc1714c1c...  catalog...buuid/master
 soundexb870344d2cae6764234...  catalog soundex
 threading  de68f80c91b47b58607...  catalog...th=threading
 [13 auto-installed packages not shown]
 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: How do I get (system-tzid) to return the correct value?

2019-02-21 Thread Brian Adkins
On Thursday, February 21, 2019 at 9:54:23 PM UTC-5, Jon Zeppieri wrote:
>
>
>
> On Thu, Feb 21, 2019 at 9:48 PM Brian Adkins  > wrote:
>
>> On Thursday, February 21, 2019 at 9:35:58 PM UTC-5, Brian Adkins wrote:
>>>
>>> On Thursday, February 21, 2019 at 9:26:07 PM UTC-5, Brian Adkins wrote:

 I'm using the (today) function from the gregor library. It was 
 returning tomorrow instead of today, so I thought the problem was the 
 timezone on my Ubuntu server. I configured the timezone to be US/Eastern 
 via: sudo dpkg-reconfigure tzdata

 Now the date command returns:  Thu Feb 21 21:23:43 EST 2019   as 
 expected.

 Unfortunately, (system-tzid) returns:  "Etc/UTC"

 So, gregor's (today) still returns tomorrow (since it's so late).

 Anyone know how to get (system-tzid) to return the correct value on 
 Ubuntu?

>>>
>>> Some more info:
>>>
>>> /etc/localtime is linked as:  localtime -> 
>>> /usr/share/zoneinfo/US/Eastern 
>>>
>>
>> I reinvoked sudo dpkg-reconfigure tzdata  and chose America/New_York  
>> instead of  US/Eastern, but I still get the default "Etc/UTC" from 
>> (system-tzid) 
>>
>
>
> Huh. Could you do the following and tell me what you get?
>
> > (require tzinfo/private/generics)
> > (require tzinfo/private/zoneinfo)
> > (define zi (make-zoneinfo-source))
> > (zoneinfo-dir zi)
> "/usr/share/zoneinfo"
> > (detect-system-tzid zi)
> "America/New_York"
>

> (require tzinfo/private/generics)
> (require tzinfo/private/zoneinfo)
> (define zi (make-zoneinfo-source))
> (zoneinfo-dir zi)
"/usr/share/zoneinfo"
> (detect-system-tzid zi)
#f

Also:

$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 36 Feb 21 21:45 /etc/localtime -> 
/usr/share/zoneinfo/America/New_York

$ cat /etc/timezone
America/New_York
 

>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] "table" data structure in Racket

2019-02-21 Thread travis . hinkelman
After posing the question yesterday, I spent a little time poking around in 
the Github repository for Apache Arrow and came to the same conclusion, 
i.e., large project presumably facilitated by corporate backing.


On Thursday, February 21, 2019 at 4:28:55 PM UTC-8, Alex Harsanyi wrote:
>
>
>
> On Thursday, February 21, 2019 at 7:19:39 AM UTC+8, travis.h...@gmail.com 
> wrote:
>>
>> Hi All,
>>
>> I'm resurrecting this thread to ask if anyone in the Racket community has 
>> Apache Arrow on their radar. It seems like Apache Arrow might be gaining 
>> steam.
>>
>
>> Apache Arrow is a cross-language development platform for in-memory data. 
>>> It specifies a standardized language-independent columnar memory format for 
>>> flat and hierarchical data, organized for efficient analytic operations on 
>>> modern hardware. It also provides computational libraries and zero-copy 
>>> streaming messaging and interprocess communication. Languages currently 
>>> supported include C, C++, C#, Go, Java, JavaScript, MATLAB, Python, R, 
>>> Ruby, and Rust. [Source 
>>> 
>>> ]
>>
>>
>> I have no clue what it would take to make Racket a supported language. I 
>> also don't have a sense of what kind of demand the Racket community has for 
>> this sort of thing. Just curious if anyone is thinking about a Racket and 
>> Apache Arrow pairing.
>>
>>
> I had looked at Apache Arrow when it was first mentioned in this thread, 
> but the project is large and providing bindings seemed like a large task -- 
> the Java, Rust, JavaScript and Python bindings are large projects by 
> themselves.  I suspect Apache Arrow (along with numpy and other scientific 
> / data-processing packages) are backed by several large companies who 
> provide the development resources.
>
> Providing usable Racket bindings for Apache Arrow is not something one can 
> do as a hobby in a few weekends.  I ended up writing my own data frame 
> package, which is smaller, simpler and has the features and performance 
> levels that I need.
>
> Alex. 
>  
>
>> Thanks,
>>
>> Travis 
>>
>> On Wednesday, April 6, 2016 at 1:27:56 AM UTC-7, Konrad Hinsen wrote:
>>>
>>> On 05/04/2016 21:12, Asumu Takikawa wrote: 
>>>
>>> > I haven't built anything like that, but I was hoping that we could get 
>>> a GSoC 
>>> > student for it (that didn't pan out though obviously). The idea was to 
>>> use 
>>> > packages from Python/Julia/R as inspiration: 
>>> > 
>>> >http://pandas.pydata.org/pandas-docs/stable/index.html 
>>> >http://dataframesjl.readthedocs.org/en/latest/ 
>>> >https://github.com/Rdatatable/data.table/wiki 
>>>
>>> Also consider this one: 
>>>
>>> https://arrow.apache.org/ 
>>>
>>> Konrad. 
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: How do I get (system-tzid) to return the correct value?

2019-02-21 Thread Jon Zeppieri
On Thu, Feb 21, 2019 at 9:48 PM Brian Adkins  wrote:

> On Thursday, February 21, 2019 at 9:35:58 PM UTC-5, Brian Adkins wrote:
>>
>> On Thursday, February 21, 2019 at 9:26:07 PM UTC-5, Brian Adkins wrote:
>>>
>>> I'm using the (today) function from the gregor library. It was returning
>>> tomorrow instead of today, so I thought the problem was the timezone on my
>>> Ubuntu server. I configured the timezone to be US/Eastern via: sudo
>>> dpkg-reconfigure tzdata
>>>
>>> Now the date command returns:  Thu Feb 21 21:23:43 EST 2019   as
>>> expected.
>>>
>>> Unfortunately, (system-tzid) returns:  "Etc/UTC"
>>>
>>> So, gregor's (today) still returns tomorrow (since it's so late).
>>>
>>> Anyone know how to get (system-tzid) to return the correct value on
>>> Ubuntu?
>>>
>>
>> Some more info:
>>
>> /etc/localtime is linked as:  localtime -> /usr/share/zoneinfo/US/Eastern
>>
>
> I reinvoked sudo dpkg-reconfigure tzdata  and chose America/New_York
> instead of  US/Eastern, but I still get the default "Etc/UTC" from
> (system-tzid)
>


Huh. Could you do the following and tell me what you get?

> (require tzinfo/private/generics)
> (require tzinfo/private/zoneinfo)
> (define zi (make-zoneinfo-source))
> (zoneinfo-dir zi)
"/usr/share/zoneinfo"
> (detect-system-tzid zi)
"America/New_York"

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: How do I get (system-tzid) to return the correct value?

2019-02-21 Thread Brian Adkins
On Thursday, February 21, 2019 at 9:35:58 PM UTC-5, Brian Adkins wrote:
>
> On Thursday, February 21, 2019 at 9:26:07 PM UTC-5, Brian Adkins wrote:
>>
>> I'm using the (today) function from the gregor library. It was returning 
>> tomorrow instead of today, so I thought the problem was the timezone on my 
>> Ubuntu server. I configured the timezone to be US/Eastern via: sudo 
>> dpkg-reconfigure tzdata
>>
>> Now the date command returns:  Thu Feb 21 21:23:43 EST 2019   as expected.
>>
>> Unfortunately, (system-tzid) returns:  "Etc/UTC"
>>
>> So, gregor's (today) still returns tomorrow (since it's so late).
>>
>> Anyone know how to get (system-tzid) to return the correct value on 
>> Ubuntu?
>>
>
> Some more info:
>
> /etc/localtime is linked as:  localtime -> /usr/share/zoneinfo/US/Eastern 
>

I reinvoked sudo dpkg-reconfigure tzdata  and chose America/New_York  
instead of  US/Eastern, but I still get the default "Etc/UTC" from 
(system-tzid) 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: How do I get (system-tzid) to return the correct value?

2019-02-21 Thread Brian Adkins
On Thursday, February 21, 2019 at 9:26:07 PM UTC-5, Brian Adkins wrote:
>
> I'm using the (today) function from the gregor library. It was returning 
> tomorrow instead of today, so I thought the problem was the timezone on my 
> Ubuntu server. I configured the timezone to be US/Eastern via: sudo 
> dpkg-reconfigure tzdata
>
> Now the date command returns:  Thu Feb 21 21:23:43 EST 2019   as expected.
>
> Unfortunately, (system-tzid) returns:  "Etc/UTC"
>
> So, gregor's (today) still returns tomorrow (since it's so late).
>
> Anyone know how to get (system-tzid) to return the correct value on Ubuntu?
>

Some more info:

/etc/localtime is linked as:  localtime -> /usr/share/zoneinfo/US/Eastern 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] How do I get (system-tzid) to return the correct value?

2019-02-21 Thread Brian Adkins
I'm using the (today) function from the gregor library. It was returning 
tomorrow instead of today, so I thought the problem was the timezone on my 
Ubuntu server. I configured the timezone to be US/Eastern via: sudo 
dpkg-reconfigure tzdata

Now the date command returns:  Thu Feb 21 21:23:43 EST 2019   as expected.

Unfortunately, (system-tzid) returns:  "Etc/UTC"

So, gregor's (today) still returns tomorrow (since it's so late).

Anyone know how to get (system-tzid) to return the correct value on Ubuntu?

Thanks,
Brian

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] "table" data structure in Racket

2019-02-21 Thread Alex Harsanyi


On Thursday, February 21, 2019 at 7:19:39 AM UTC+8, travis.h...@gmail.com 
wrote:
>
> Hi All,
>
> I'm resurrecting this thread to ask if anyone in the Racket community has 
> Apache Arrow on their radar. It seems like Apache Arrow might be gaining 
> steam.
>

> Apache Arrow is a cross-language development platform for in-memory data. 
>> It specifies a standardized language-independent columnar memory format for 
>> flat and hierarchical data, organized for efficient analytic operations on 
>> modern hardware. It also provides computational libraries and zero-copy 
>> streaming messaging and interprocess communication. Languages currently 
>> supported include C, C++, C#, Go, Java, JavaScript, MATLAB, Python, R, 
>> Ruby, and Rust. [Source 
>> 
>> ]
>
>
> I have no clue what it would take to make Racket a supported language. I 
> also don't have a sense of what kind of demand the Racket community has for 
> this sort of thing. Just curious if anyone is thinking about a Racket and 
> Apache Arrow pairing.
>
>
I had looked at Apache Arrow when it was first mentioned in this thread, 
but the project is large and providing bindings seemed like a large task -- 
the Java, Rust, JavaScript and Python bindings are large projects by 
themselves.  I suspect Apache Arrow (along with numpy and other scientific 
/ data-processing packages) are backed by several large companies who 
provide the development resources.

Providing usable Racket bindings for Apache Arrow is not something one can 
do as a hobby in a few weekends.  I ended up writing my own data frame 
package, which is smaller, simpler and has the features and performance 
levels that I need.

Alex. 
 

> Thanks,
>
> Travis 
>
> On Wednesday, April 6, 2016 at 1:27:56 AM UTC-7, Konrad Hinsen wrote:
>>
>> On 05/04/2016 21:12, Asumu Takikawa wrote: 
>>
>> > I haven't built anything like that, but I was hoping that we could get 
>> a GSoC 
>> > student for it (that didn't pan out though obviously). The idea was to 
>> use 
>> > packages from Python/Julia/R as inspiration: 
>> > 
>> >http://pandas.pydata.org/pandas-docs/stable/index.html 
>> >http://dataframesjl.readthedocs.org/en/latest/ 
>> >https://github.com/Rdatatable/data.table/wiki 
>>
>> Also consider this one: 
>>
>> https://arrow.apache.org/ 
>>
>> Konrad. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How do you make students submit programming assignments online for automatic tests?

2019-02-21 Thread Jordan Johnson
On Feb 20, 2019, at 10:40, 'John Clements' via Racket Users 
 wrote:
> One solution would be to use the command-line version of Racket’s 
> handin-server, which is language-agnostic to the degree that it can just 
> submit arbitrary files to the server, and what happens on the back end is up 
> to you
> 
> I look forward to hearing about anything awesome that others use.

I’ve been working on making the handin server fit the way I think about things, 
and I’m hoping to get my code to the point where “awesome” would be a 
reasonable descriptor.

Here’s a sketch of the core ideas.

1) I want to be able to code up a solution for each assignment I write, and use 
the solution file in assessing student work. My students’ work is in *SL, so I 
want to write my solutions in that language as well. I have a library that 
provides macros check-expect*, check-within*, etc; they expand to check-expect 
& co for use on my own code, but they also get collected as tests to run on 
student submissions. The library makes my solution file provide a handle on 
these tests, so I can just require my solution file from the checker.

2) I want automated checking that the student has defined all the 
functions/constants that I’ve explicitly named in the assignment, and I do this 
via a students-must-define macro that the solution library provides; again, my 
resulting assignment solution file then provides a handle on the required names.

I'm satisfied that the above two points are clear wins, at least for me; the 
interface is comfortable to work with.

3) I use the web-server/templates library to generate a partially-filled rubric 
based on the solution file. For each assignment I include a rubric (.txt file) 
in the assignment directory for this purpose.

4) I want the code that actually resides in checker.rkt to be about how to 
respond to student code passing or failing the desiderata I’ve set out in the 
solution file, rather than about what the student should  define and what tests 
should run.

I also want to incorporate some cosmetic checks (like indentation) but haven’t 
gotten around to it yet.

My motivation in all this is that the convenience of submitting from DrR is 
great, but I’ve found it hard to write checkers that yield good UX for students 
whose work is imperfect. The typical failure mode is that errors are raised and 
handin fails; I generally would rather accept the handin and log its 
shortcomings in the rubric, and sometimes also give the student a notification 
(like, “hey, please break your long lines and re-submit”).

Longer term I’d like to come up with something to serve as an instructor 
dashboard, with an aggregate display of features like who left what function 
undefined, and what tests were failed by multiple students’ code.

If I get to a point where I’m satisfied that the end product is useful enough 
to warrant sharing, I’ll write it all up and share the code. If anybody wants 
to collaborate I’d be happy to discuss and share off-list.

Best,
J

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Help with generators from python land!

2019-02-21 Thread Dave McDaniel
Yes, that is a key difference to the extent of the laziness I think.  The 
python generator is different than `for` in racket as what is returned from 
calling a generator function in python is not a list at all, its a 
generator that must be externally driven in order to produce values.  
Whereas the result of calling `for/list` is an actual fully populated 
list.  The python generator's yield statement is also at the core of its 
newish async style single threaded concurrency, which is a bit of a hacked 
add-on given that the language wasn't originally designed with concurrency 
in mind.  I believe the parallel to python's asyncio in racket probably has 
to do with delimited continuations but I'll save that question for the 
future once I better understand what those are!

On Thursday, February 21, 2019 at 3:44:40 PM UTC-5, Zelphir Kaltstahl wrote:
>
> Ah, you are of course right. Somehow I thought about `for/list` and 
> returning lists and then doing something on the returned list, instead 
> of simply doing it _inside_ the `for`. Apologies! 
>
> On 2/21/19 8:46 PM, Robby Findler wrote: 
> > For the record, `for` iterators go element-by-element. For example, 
> > this program does not construct anything that has all of the natural 
> > numbers in it: 
> > 
> > #lang racket 
> > 
> > (define my-stuffs-value 
> >   (hash 'telephone 3 
> > 'bluejeans 24 
> > 'house 10 
> > 'computer 3000)) 
> > 
> > (define my-estates-value 
> >   (for/sum ([i (in-naturals)] 
> > [(k v) (in-hash my-stuffs-value)]) 
> > (printf "item ~a is worth ~a\n" i v) 
> > v)) 
> > 
> > my-estates-value 
> > 
> > On Thu, Feb 21, 2019 at 1:40 PM Zelphir Kaltstahl 
> > > wrote: 
> >> I don't think one can see `for` in Racket as equivalent to generators 
> in Python. 
> >> 
> >> Generators in Python are used when you want to save memory by not 
> producing all values at once, but want to go value by value (which to my 
> knowledge Racket's `for` variants do not do, but I'd like to be corrected, 
> if I am wrong about this, as it would mean, that those `for` are even more 
> awesome than I knew.) They are more like lazy possibly infinite lists. I 
> think lazy Racket has that and that there was some advice about not calling 
> `length` on an infinite list. 
> >> 
> >> Python, I believe, has some kind of `Iterable` interface, which a 
> generator satisfies and which specifies the method to call to get the next 
> value. In Racket maybe one would have to do with a convention of how to get 
> a next value from a lazy list. 
> >> 
> >> I believe something like the following could be an example. I did not 
> yet think about macros, nor am I experienced with that, so maybe one can 
> create something more elegant than what I am posting: 
> >> 
> >> ~~~ 
> >> #lang racket 
> >> 
> >> ;;  
> >> ;; DATA ABSTRACTION 
> >> ;;  
> >> 
> >> ;; The value is always the first value of the generator. 
> >> (define get-value car) 
> >> 
> >> ;; A generator's producing procedure needs to be applied to get the 
> >> ;; next thing. 
> >> (define (get-next a-gen) 
> >>   ((cdr a-gen))) 
> >> 
> >> ;; A generator is only a tuple containing the current value and the 
> >> ;; procedure to create the next value 
> >> (define (make-gen proc start) 
> >>   (cons start 
> >> (lambda () 
> >>   (make-gen proc (proc start) 
> >> 
> >> (define STOP-SYMBOL 'none) 
> >> 
> >> ;;  
> >> ;; EXAMPLES 
> >> ;;  
> >> 
> >> ;; An infinite list of numbers. 
> >> (define natural-numbers 
> >>   (make-gen (lambda (x) (+ x 1)) 
> >> 0)) 
> >> 
> >> ;; A limited list of natural numbers. 
> >> (define (limited-natural-numbers limit) 
> >>   (make-gen (lambda (x) 
> >>   (cond [(< x limit) (+ x 1)] 
> >> [else STOP-SYMBOL])) 
> >> 0)) 
> >> 
> >> ;; Print a certain amount of natural numbers. 
> >> (define (print-natural-numbers natural-numbers limit) 
> >>   (let ([current-number (get-value natural-numbers)]) 
> >> (cond 
> >>   [(and (symbol? current-number) (symbol=? current-number 
> STOP-SYMBOL)) 
> >>(displayln "No more numbers available!")] 
> >>   [(< current-number limit) 
> >>(displayln current-number) 
> >>(print-natural-numbers (get-next natural-numbers) limit)] 
> >>   [else 
> >>(displayln "Done")]))) 
> >> ~~~ 
> >> 
> >> Here the conventions are the structure of the generator and the stop 
> symbol. In Python those are already taken care of by the standard library's 
> generator interface. 
> >> 
> >> 
> >> On Wednesday, February 20, 2019 at 10:10:16 PM UTC, Jens Axel Søgaard 
> wrote: 
> >>> Den ons. 20. feb. 2019 kl. 22.25 skrev Dave McDaniel <
> mcdani...@gmail.com>: 
>  Hello, 
>  
>  I have interest in picking up racket and have done some koans and 
> also have been doing the racket track on exercism. 
>  
>  There is a fairly s

Re: [racket-users] Help with generators from python land!

2019-02-21 Thread Zelphir Kaltstahl
Ah, you are of course right. Somehow I thought about `for/list` and
returning lists and then doing something on the returned list, instead
of simply doing it _inside_ the `for`. Apologies!

On 2/21/19 8:46 PM, Robby Findler wrote:
> For the record, `for` iterators go element-by-element. For example,
> this program does not construct anything that has all of the natural
> numbers in it:
>
> #lang racket
>
> (define my-stuffs-value
>   (hash 'telephone 3
> 'bluejeans 24
> 'house 10
> 'computer 3000))
>
> (define my-estates-value
>   (for/sum ([i (in-naturals)]
> [(k v) (in-hash my-stuffs-value)])
> (printf "item ~a is worth ~a\n" i v)
> v))
>
> my-estates-value
>
> On Thu, Feb 21, 2019 at 1:40 PM Zelphir Kaltstahl
>  wrote:
>> I don't think one can see `for` in Racket as equivalent to generators in 
>> Python.
>>
>> Generators in Python are used when you want to save memory by not producing 
>> all values at once, but want to go value by value (which to my knowledge 
>> Racket's `for` variants do not do, but I'd like to be corrected, if I am 
>> wrong about this, as it would mean, that those `for` are even more awesome 
>> than I knew.) They are more like lazy possibly infinite lists. I think lazy 
>> Racket has that and that there was some advice about not calling `length` on 
>> an infinite list.
>>
>> Python, I believe, has some kind of `Iterable` interface, which a generator 
>> satisfies and which specifies the method to call to get the next value. In 
>> Racket maybe one would have to do with a convention of how to get a next 
>> value from a lazy list.
>>
>> I believe something like the following could be an example. I did not yet 
>> think about macros, nor am I experienced with that, so maybe one can create 
>> something more elegant than what I am posting:
>>
>> ~~~
>> #lang racket
>>
>> ;; 
>> ;; DATA ABSTRACTION
>> ;; 
>>
>> ;; The value is always the first value of the generator.
>> (define get-value car)
>>
>> ;; A generator's producing procedure needs to be applied to get the
>> ;; next thing.
>> (define (get-next a-gen)
>>   ((cdr a-gen)))
>>
>> ;; A generator is only a tuple containing the current value and the
>> ;; procedure to create the next value
>> (define (make-gen proc start)
>>   (cons start
>> (lambda ()
>>   (make-gen proc (proc start)
>>
>> (define STOP-SYMBOL 'none)
>>
>> ;; 
>> ;; EXAMPLES
>> ;; 
>>
>> ;; An infinite list of numbers.
>> (define natural-numbers
>>   (make-gen (lambda (x) (+ x 1))
>> 0))
>>
>> ;; A limited list of natural numbers.
>> (define (limited-natural-numbers limit)
>>   (make-gen (lambda (x)
>>   (cond [(< x limit) (+ x 1)]
>> [else STOP-SYMBOL]))
>> 0))
>>
>> ;; Print a certain amount of natural numbers.
>> (define (print-natural-numbers natural-numbers limit)
>>   (let ([current-number (get-value natural-numbers)])
>> (cond
>>   [(and (symbol? current-number) (symbol=? current-number STOP-SYMBOL))
>>(displayln "No more numbers available!")]
>>   [(< current-number limit)
>>(displayln current-number)
>>(print-natural-numbers (get-next natural-numbers) limit)]
>>   [else
>>(displayln "Done")])))
>> ~~~
>>
>> Here the conventions are the structure of the generator and the stop symbol. 
>> In Python those are already taken care of by the standard library's 
>> generator interface.
>>
>>
>> On Wednesday, February 20, 2019 at 10:10:16 PM UTC, Jens Axel Søgaard wrote:
>>> Den ons. 20. feb. 2019 kl. 22.25 skrev Dave McDaniel :
 Hello,

 I have interest in picking up racket and have done some koans and also 
 have been doing the racket track on exercism.

 There is a fairly simple exercise called `etl` on exercism related to 
 taking a hash for scoring scrabble letters and unpacking it into a 
 flatter, more efficient structure for lookups.

 The input hash has score as the key and a list of letters of that score as 
 the value.  The output is a hash of letter -> score.  One pair per letter 
 instead of one pair per score.

 It was easy enough to solve with `for-each` using side-effects to update a 
 mutable hash, however I think using a generator is a cleaner approach and 
 doesn't require mutability.
>>>
>>> FWIW here is a solution using immutable hashes. I see `for` and friends as 
>>> Racket "generators".
>>>
>>> /Jens Axel
>>>
>>>
>>> #lang racket
>>> (require racket/hash)
>>>
>>> ; In Scrabble each letter gives a certain number of points.
>>> ; In the old data we have for each point a list of numbers,
>>> ; that awarded the given number of points.
>>>
>>> (define old-data
>>>   ; list of associations from point to list of strings (letters)
>>>   '((1  "A" "E" "I" "O" "U" "L" "N" "R" "S" "T")
>>> (2  "D" "G")
>>> (3  "B" "C" "M" "P")
>>> (4  "F" "H" "V" "W" "Y")
>>> 

[racket-users] Re: How do you make students submit programming assignments online for automatic tests?

2019-02-21 Thread Zelphir Kaltstahl
If you were using Racket, you might be interested in this RacketCon video 
(time is linked):

https://youtu.be/WI8uA4KjQJk?t=1510

Racket has a very tree like code structure right in front of the developer, 
while I guess you would have to get through to the AST in other languages, 
where that is not the case, to do something similar. I found that project 
quite impressive and I wish I had something like it for other languages. I 
think there is also a paper about it. You can find it by searching for the 
name of the speaker.

On Wednesday, February 20, 2019 at 5:51:38 PM UTC, Marc Kaufmann wrote:
>
> Hi all,
>
> I will be teaching a course on data analysis in R next year (September), 
> and may at some point add some Racketeering to my other courses (maybe), 
> and I was wondering how those of you who teach programming classes deal 
> with programming assignments. Are there somewhat language-independent 
> platforms for having students submit assignments that have to pass a bunch 
> of pre-specified tests, or would I need to look at what is available for 
> any given platform? Any security issues I should be aware of?
>
> All recommendations welcome,
>
> Marc
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Use cases for tables and records

2019-02-21 Thread jackhfirth
Hi folks! I'm looking for use cases for a few small data structure 
libraries I'm working on:

- Records , which are 
dictionaries mapping keywords to values. Keys must be keywords, which 
allows for more efficient behavior in various cases and sometimes 
cooperates nicely with keyword arguments. Example:

> (define rec (record #:person "Joe Schmoe" #:age 30 #:favorite-color 
'blue))
> (record-ref rec '#:age)
30

- Tables , which are 
like a list of records that all have the same keywords. Tables are similar 
to dataframes and are intended to make it easy to process spreadsheet-like 
data such as CSV files. Example:

(table (columns #:name #:population #:capital-city)
 (row "Argentina" 4380 "Buenos Aires")
 (row "Greece" 1080 "Athens")
 (row "Nigeria" 19860 "Abuja")
 (row "Japan" 12640 "Tokyo"))

The libraries are really just bare-bones skeletons at the moment and are 
missing a lot of core features. Still, if they seem like things that you 
would use, please let me know how! Pointers to code "in the wild" where you 
think these libraries would help are especially useful. Pointers to similar 
libraries (like the data-frame 
 package) and 
discussions about their advantages / disadvantages are also helpful.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Help with generators from python land!

2019-02-21 Thread Robby Findler
For the record, `for` iterators go element-by-element. For example,
this program does not construct anything that has all of the natural
numbers in it:

#lang racket

(define my-stuffs-value
  (hash 'telephone 3
'bluejeans 24
'house 10
'computer 3000))

(define my-estates-value
  (for/sum ([i (in-naturals)]
[(k v) (in-hash my-stuffs-value)])
(printf "item ~a is worth ~a\n" i v)
v))

my-estates-value

On Thu, Feb 21, 2019 at 1:40 PM Zelphir Kaltstahl
 wrote:
>
> I don't think one can see `for` in Racket as equivalent to generators in 
> Python.
>
> Generators in Python are used when you want to save memory by not producing 
> all values at once, but want to go value by value (which to my knowledge 
> Racket's `for` variants do not do, but I'd like to be corrected, if I am 
> wrong about this, as it would mean, that those `for` are even more awesome 
> than I knew.) They are more like lazy possibly infinite lists. I think lazy 
> Racket has that and that there was some advice about not calling `length` on 
> an infinite list.
>
> Python, I believe, has some kind of `Iterable` interface, which a generator 
> satisfies and which specifies the method to call to get the next value. In 
> Racket maybe one would have to do with a convention of how to get a next 
> value from a lazy list.
>
> I believe something like the following could be an example. I did not yet 
> think about macros, nor am I experienced with that, so maybe one can create 
> something more elegant than what I am posting:
>
> ~~~
> #lang racket
>
> ;; 
> ;; DATA ABSTRACTION
> ;; 
>
> ;; The value is always the first value of the generator.
> (define get-value car)
>
> ;; A generator's producing procedure needs to be applied to get the
> ;; next thing.
> (define (get-next a-gen)
>   ((cdr a-gen)))
>
> ;; A generator is only a tuple containing the current value and the
> ;; procedure to create the next value
> (define (make-gen proc start)
>   (cons start
> (lambda ()
>   (make-gen proc (proc start)
>
> (define STOP-SYMBOL 'none)
>
> ;; 
> ;; EXAMPLES
> ;; 
>
> ;; An infinite list of numbers.
> (define natural-numbers
>   (make-gen (lambda (x) (+ x 1))
> 0))
>
> ;; A limited list of natural numbers.
> (define (limited-natural-numbers limit)
>   (make-gen (lambda (x)
>   (cond [(< x limit) (+ x 1)]
> [else STOP-SYMBOL]))
> 0))
>
> ;; Print a certain amount of natural numbers.
> (define (print-natural-numbers natural-numbers limit)
>   (let ([current-number (get-value natural-numbers)])
> (cond
>   [(and (symbol? current-number) (symbol=? current-number STOP-SYMBOL))
>(displayln "No more numbers available!")]
>   [(< current-number limit)
>(displayln current-number)
>(print-natural-numbers (get-next natural-numbers) limit)]
>   [else
>(displayln "Done")])))
> ~~~
>
> Here the conventions are the structure of the generator and the stop symbol. 
> In Python those are already taken care of by the standard library's generator 
> interface.
>
>
> On Wednesday, February 20, 2019 at 10:10:16 PM UTC, Jens Axel Søgaard wrote:
>>
>> Den ons. 20. feb. 2019 kl. 22.25 skrev Dave McDaniel :
>>>
>>> Hello,
>>>
>>> I have interest in picking up racket and have done some koans and also have 
>>> been doing the racket track on exercism.
>>>
>>> There is a fairly simple exercise called `etl` on exercism related to 
>>> taking a hash for scoring scrabble letters and unpacking it into a flatter, 
>>> more efficient structure for lookups.
>>>
>>> The input hash has score as the key and a list of letters of that score as 
>>> the value.  The output is a hash of letter -> score.  One pair per letter 
>>> instead of one pair per score.
>>>
>>> It was easy enough to solve with `for-each` using side-effects to update a 
>>> mutable hash, however I think using a generator is a cleaner approach and 
>>> doesn't require mutability.
>>
>>
>> FWIW here is a solution using immutable hashes. I see `for` and friends as 
>> Racket "generators".
>>
>> /Jens Axel
>>
>>
>> #lang racket
>> (require racket/hash)
>>
>> ; In Scrabble each letter gives a certain number of points.
>> ; In the old data we have for each point a list of numbers,
>> ; that awarded the given number of points.
>>
>> (define old-data
>>   ; list of associations from point to list of strings (letters)
>>   '((1  "A" "E" "I" "O" "U" "L" "N" "R" "S" "T")
>> (2  "D" "G")
>> (3  "B" "C" "M" "P")
>> (4  "F" "H" "V" "W" "Y")
>> (5  "K")
>> (8  "J" "X")
>> (10 "Q" "Z")))
>>
>>
>> ; Each point list needs to be transformed to a
>> ; hash table from letters to points.
>>
>> (define (transform association)
>>   (match association
>> [(list point letters ...)
>>  (for/hash ([letter letters])
>>(values (string-downcase letter) point))]))
>>
>> ; Now we only need to combine th

Re: [racket-users] Help with generators from python land!

2019-02-21 Thread Zelphir Kaltstahl
I don't think one can see `for` in Racket as equivalent to generators in 
Python.

Generators in Python are used when you want to save memory by not producing 
all values at once, but want to go value by value (which to my knowledge 
Racket's `for` variants do not do, but I'd like to be corrected, if I am 
wrong about this, as it would mean, that those `for` are even more awesome 
than I knew.) They are more like lazy possibly infinite lists. I think lazy 
Racket has that and that there was some advice about not calling `length` 
on an infinite list.

Python, I believe, has some kind of `Iterable` interface, which a generator 
satisfies and which specifies the method to call to get the next value. In 
Racket maybe one would have to do with a convention of how to get a next 
value from a lazy list.

I believe something like the following could be an example. I did not yet 
think about macros, nor am I experienced with that, so maybe one can create 
something more elegant than what I am posting:

~~~
#lang racket

;; 
;; DATA ABSTRACTION
;; 

;; The value is always the first value of the generator.
(define get-value car)

;; A generator's producing procedure needs to be applied to get the
;; next thing.
(define (get-next a-gen)
  ((cdr a-gen)))

;; A generator is only a tuple containing the current value and the
;; procedure to create the next value
(define (make-gen proc start)
  (cons start
(lambda ()
  (make-gen proc (proc start)

(define STOP-SYMBOL 'none)

;; 
;; EXAMPLES
;; 

;; An infinite list of numbers.
(define natural-numbers
  (make-gen (lambda (x) (+ x 1))
0))

;; A limited list of natural numbers.
(define (limited-natural-numbers limit)
  (make-gen (lambda (x)
  (cond [(< x limit) (+ x 1)]
[else STOP-SYMBOL]))
0))

;; Print a certain amount of natural numbers.
(define (print-natural-numbers natural-numbers limit)
  (let ([current-number (get-value natural-numbers)])
(cond
  [(and (symbol? current-number) (symbol=? current-number STOP-SYMBOL))
   (displayln "No more numbers available!")]
  [(< current-number limit)
   (displayln current-number)
   (print-natural-numbers (get-next natural-numbers) limit)]
  [else
   (displayln "Done")])))
~~~

Here the conventions are the structure of the generator and the stop 
symbol. In Python those are already taken care of by the standard library's 
generator interface.


On Wednesday, February 20, 2019 at 10:10:16 PM UTC, Jens Axel Søgaard wrote:
>
> Den ons. 20. feb. 2019 kl. 22.25 skrev Dave McDaniel  >:
>
>> Hello,
>>
>> I have interest in picking up racket and have done some koans and also 
>> have been doing the racket track on exercism.
>>
>> There is a fairly simple exercise called `etl` on exercism related to 
>> taking a hash for scoring scrabble letters and unpacking it into a flatter, 
>> more efficient structure for lookups.
>>
>> The input hash has score as the key and a list of letters of that score 
>> as the value.  The output is a hash of letter -> score.  One pair per 
>> letter instead of one pair per score.
>>
>> It was easy enough to solve with `for-each` using side-effects to update 
>> a mutable hash, however I think using a generator is a cleaner approach and 
>> doesn't require mutability.  
>>
>
> FWIW here is a solution using immutable hashes. I see `for` and friends as 
> Racket "generators". 
>
> /Jens Axel
>
>
> #lang racket
> (require racket/hash)
>
> ; In Scrabble each letter gives a certain number of points.
> ; In the old data we have for each point a list of numbers,
> ; that awarded the given number of points.
>
> (define old-data
>   ; list of associations from point to list of strings (letters)
>   '((1  "A" "E" "I" "O" "U" "L" "N" "R" "S" "T")
> (2  "D" "G")
> (3  "B" "C" "M" "P")
> (4  "F" "H" "V" "W" "Y")
> (5  "K")
> (8  "J" "X")
> (10 "Q" "Z")))
>
>
> ; Each point list needs to be transformed to a
> ; hash table from letters to points.
>
> (define (transform association)
>   (match association
> [(list point letters ...)
>  (for/hash ([letter letters])
>(values (string-downcase letter) point))]))
>
> ; Now we only need to combine the hash lists.
> (define ht
>   (apply hash-union
>(hash)
>(for/list ([association old-data])
>  (transform association
>
> (define (lookup letter)
>   (hash-ref ht letter #f))
>
> (lookup "e")
> (lookup "x")
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Help with generators from python land!

2019-02-21 Thread Dave McDaniel
Hi Jon,

Thanks for the very detailed explanation.  It does make good sense and is 
helpful in getting up to speed on racket in general.  Regarding the docs, 
it does not say "slight", but rather "can provide better", I read this as 
slight since it wasn't definitive--but I understand better now based on 
your description in which case (`for`) it is an optimization.

Thanks again,
Dave

An in-list 
> 
>  
> application can provide better performance for list iteration when it 
> appears directly in a for 
> 
>  
> clause.
>

On Wednesday, February 20, 2019 at 10:00:54 PM UTC-5, Jon Zeppieri wrote:
>
>
> On Wed, Feb 20, 2019 at 9:14 PM Dave McDaniel  > wrote:
>
>> Thanks Jon and Jen, This is a great!  I figured there must be a 
>> straightforward way to do this with a `for/hash` implementation.  I have 
>> not seen these 2 methods `in-hash` and `in-list` vs just using the hash or 
>> list without that sequence modifier.  Can you comment on what is going on 
>> with this `in-xxx` sequence modification?  The docs indicate that you get 
>> slightly better performance when using these with `for`, but its not clear 
>> why and in what situations you must use these modifiers rather than the 
>> underlying list or hash itself--is it always optional?
>>
>
> `in-hash` and `in-list` are optional, but, as you noted, they do make 
> iteration perform better.[*] This is because the various iterators can 
> generate better code if they know what kind of sequence they're dealing 
> with. If they don't know, they have to use generic sequence operations, 
> which are usually quite a lot less efficient. The difference is not slight. 
> (Do the docs say it is?) 
>
> That said, if you're only iterating over a small sequence, you won't 
> notice or care.
>
> You can see the difference in generated code by using the Macro Stepper in 
> Dr. Racket. Write something like:
> ```
> #lang racket/base
>
> (define (fast-foo xs)
>   (for/list ([x (in-list xs)])
> x))
>
> (define (slow-foo xs)
>   (for/list ([x xs])
> x))
> ```
>
> Then click on the Macro Stepper button and then click "End" to see the 
> fully expanded source, and compare the two different versions.
>
> [*] Rather, they make iteration perform better when they're used inside a 
> `for` loop. Outside of a `for`, they're just normal procedures. Inside, 
> they are syntax and direct code generation. You would _not_ get better 
> performance from:
>
> (slow-foo (in-list my-list))
>   than you would from
> (slow-foo my-list)
>
> ==
>
> However, it's not the case that the `in-` syntax is always 
> optional. For example, if you have a hash, then
>
> (for ([(k v) hash]) ...)
>   and
> (for ([(k v) (in-hash hash)]) ...)
>
> will always have the same behavior (though not performance). But if you 
> want to iterate over explicit key/value _pairs_ (i.e., cons cells), then 
> you'd need to do:
>
> (for ([pair (in-hash-pairs hash)]) ...)
>
> since the default sequence interpretation for a hash is one that produces 
> two values (the key and value) per-iteration, instead of one that produces 
> a single cons cell value per-iteration.
>
> Point is, sometimes `in-` is an optimization; in other cases, it 
> changes the actual way that the data structure is interpreted as a sequence.
>
> - Jon
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.