Re: [racket-users] Decision Tree in Racket - Performance

2017-07-23 Thread Jon Zeppieri
On Sun, Jul 23, 2017 at 8:43 PM, David Storrs <david.sto...@gmail.com> wrote:
>
>
> On Sun, Jul 23, 2017 at 8:05 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
>> - Use a struct instead of a hash to represent a split.
>
>
> Oh, are structs faster than hashes?

Can't make a blanket statement, and the best reason to use a struct in
this case has nothing to do with performance; it's simply that the
code wants an associative data structure with a set of labels (keys)
that are known in advance. The keys aren't really data in this case.

Anyhow, on the matter of performance:

First, there's no hashing involved in struct lookup (which is just an
indexed load) or update. That's already a point in the struct's favor.
Struct update does, however, involve a full copy, so overall
performance will depend on just how much data needs to be copied. In
this case, the structs/hashes have only four keys/labels. And
immutable hashes have a more complex representation and a larger
constant-time overhead. So, I would expect structs to perform better
here, but I doubt that the difference is a big deal.

-- 
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] Decision Tree in Racket - Performance

2017-07-23 Thread Jon Zeppieri
On Sun, Jul 23, 2017 at 7:30 PM, Zelphir Kaltstahl
 wrote:
> Hi Racket Users,
>
> The last few days I've been working on implementing decision trees in Racket 
> and I've been following the following guide: 
> http://machinelearningmastery.com/implement-decision-tree-algorithm-scratch-python/
>
> Now I have the following code: https://github.com/ZelphirKaltstahl/racket-ml
>
> I also wrote some tests, I think for every procedure so far.
>
> However, my implementation seems very very slow. It seems each iteration of 
> `iter-features` takes way too much time.
>
> I've tried to stick to the guide and sometimes "outsourced" some procedure.
>
> I started out with using vectors, as I thought I might gain better 
> performance than from lists. In the code I introduced an abstraction layer, 
> which provides things like `data-length`, so that I could in theory change 
> the representation of data and only change those accessors/getters. In the 
> test cases I sometimes did not use the abstraction though.
>
> So far I am not having much side effects in the code and I'd like to avoid 
> them and unsafe operations.
>
> A small `TEST-DATA` set is in the code and another data set I downloaded from 
> the data set repositories. When running with `TEST-DATA` to calculate the 
> best split, it only takes a few milliseconds, while it takes minutes with the 
> other `data-set`.
>
> How can I make my code more efficient, without changing the basic logic of it?
> Should I not use vectors (what else?)?
> Would I gain anything from using typed Racket or flonums?
>


I haven't taken a close enough look to evaluate the algorithm itself,
but on a micro-scale:

- Using `vector-take-right` to get the tail of a vector in a loop is
expensive. From what I can see, you'll be better off representing your
data as a list of vectors. (I see you have a `data-get-row` function,
suggesting a need for random access, but you don't appear to be using
it.)
- Use a struct instead of a hash to represent a split.
- `split-data` could partition the data list in a single pass, instead
of making two passes. (You can use the `partition` function from
racket/list.)
- If I'm reading this right, for a given data set, you should be able
to memoize calls to `data-get-col`.
- From a quick glance, it looks like you're already using floats,
rather than exact rationals.
- Are you running this code inside DrRacket? If so, have you timed the
difference between running it with debugging enabled and with no
debugging or profiling? (Language -> Choose Language... -> Details)

-- 
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] IO in racket is painful

2017-07-22 Thread Jon Zeppieri
On Sat, Jul 22, 2017 at 3:30 PM, David Storrs  wrote:
>
> Alternatively, if 'match' made the results of a successful regexp test
> available to the bodies on the RHS then you could do the same thing by
> accessing the result list.  Perhaps if match would allow the RHS to be a
> function?
>
> (match "foo"
>   [#px"oo.+(.)" (lambda (res) (println (~a "Regexp match results were: "
> res)))])
>
> Output:
> '("oobar" "r")
>

This, at least, already exists:

(match "foobar"
  [(pregexp #px"oo.+(.)" res)
   (println (~a "Regexp match results were: " res))])

-- 
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] for/list with in-parallel lists

2017-07-10 Thread Jon Zeppieri
On Tue, Jul 11, 2017 at 12:56 AM, Alex Knauth  wrote:
>
> You can do this with the Generic Bind package [1].

Oh, this is very nice. Thank you. -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] for/list with in-parallel lists

2017-07-10 Thread Jon Zeppieri
On Tue, Jul 11, 2017 at 12:28 AM, Jon Zeppieri <zeppi...@gmail.com> wrote:
>
> As far as I know, there's nothing built-in that does this, but it's
> not hard to build:
>

... though a syntactic solution combining for and match would probably
be better.

-- 
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] for/list with in-parallel lists

2017-07-10 Thread Jon Zeppieri
On Tue, Jul 11, 2017 at 12:16 AM, Nadeem Abdul Hamid  wrote:
> I'm looking for a general solution. Basically, I thought binding multiple
> id's would have achieved what this does:
>
>> (for/list ([t '((1 2 3) (4 5 6) (7 8 9) (a b c))])
> (match-define (list x y z) t)
> (list x z))
> '((1 3) (4 6) (7 9) (a c))
>

As far as I know, there's nothing built-in that does this, but it's
not hard to build:

(define (in-tuples xs)
  (make-do-sequence
   (λ ()
 (values
  (λ (pos)
(apply values (car pos)))
  cdr
  xs
  (λ (pos)
(not (null? pos)))
  #f
  #f

(for/list ([(x y z) (in-tuples '((1 2 3) (4 5 6) (7 8 9) (a b c)))])
  (list x z))

;; => '((1 3) (4 6) (7 9) (a c))

-- 
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] for/list with in-parallel lists

2017-07-10 Thread Jon Zeppieri
On Mon, Jul 10, 2017 at 11:40 PM, Nadeem Abdul Hamid  wrote:
> Given a list of pairs, I'm trying to iterate through the list and bind the
> first and second elements of each pair to x and y, respectively, in each
> iteration.
>
> For example, hash sets are a multiple-valued sequence[1], so this:
>(for/list ([(x y) #hash((1 . 2) (3 . 4))]) x)
> produces:
>(list 1 3)
>
> i.e. here x gets bound to 1 in the first iteration and 3 in the second. I
> would like something analogous for a list of pairs, i.e. replacing #hash
> with ' :
>(for/list ([(x y) '((1 . 2) (3 . 4))]) x)
>  except that lists are a by default a single-valued sequence[2].
>
>

in-dict will work for lists of pairs, like the ones in this example
(and it will work for hashes, as well), but it won't work for lists of
lists, like the examples in your previous message. Are lists of pairs
all you need to handle, or do you need something more general?

-- 
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] for/list with in-parallel lists

2017-07-10 Thread Jon Zeppieri
On Mon, Jul 10, 2017 at 11:02 PM, Nadeem Abdul Hamid  wrote:
> How come this:
>(for/list ([(x y) (in-parallel '(1 2) '(3 4))]) x)
> produces
>   '(1 2)
> instead of
>   '(1 3)
> ?

You're creating a list of the x values. In the first iteration x is 1,
and in the second it's 2. So the result is '(1 2). You won't see 3 in
the result, because it will be bound to y, not x, in the first
iteration.

> Whereas,
>   (sequence-ref (in-parallel '(1 2) '(3 4)) 0)
> produces
>   1
>   3
> as I would expect, but am I doing something wrong with for/list?


Here, you're getting the first element of the sequence which is (values 1 3).

>
> In general, how might one convert a list of tuples into a multiple-valued
> sequence? i.e. ideally I'd like to be able to just match:
>   (for/list ([(x y) '((1 2) (3 4))])  x)
> and have it produce
>'(1 3)

I'm not sure exactly what you're looking for, since I can't quite
square your description ("multiple-values sequence") with your example
result -- '(1 3). If that is the result you're looking for, you could
use

  (map first  '((1 2) (3 4)))

If you want to go from  '((1 2) (3 4)) to '((1 3) (2 4)), you could do

  (apply map list '((1 2) (3 4)))

And if you really do want a sequence of multiple values, you could use

  (apply in-parallel '((1 2) (3 4)))

-- 
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] Code critique (of naive code) would be very appreciated

2017-06-21 Thread Jon Zeppieri
And I should heed my own advice about testing.


On Wed, Jun 21, 2017 at 8:40 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
>
> #lang at-exp racket
>
> (define (normalize-keywords in)
>   (regexp-replace*
>@pregexp|{Keywords ?= ?\{\s*([^}]*)\}}|
>in
>(λ (_ s)

You may have noticed that I left out part of the replacement string. :)

>  (string-join
>   (map capitalize-first (regexp-split #px", *" s))
>   ", "

Ahem...

   (λ (_ s)
 (string-append
  "Keywords = {"
  (string-join
   (map capitalize-first (regexp-split #px", *" s))
   ", ")
  "}"))

-- 
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] Code critique (of naive code) would be very appreciated

2017-06-21 Thread Jon Zeppieri
On Wed, Jun 21, 2017 at 8:40 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
>
> #lang at-exp racket
>
> ;; normalize-keywords: string? -> string?
> #lang at-exp racket
>

Sorry, I made some bad edits here. Should have been:

#lang at-exp racket

;; normalize-keywords: string? -> string?
(define (normalize-keywords in)
 ...)


By the way, I failed to mention the point of `at-exp` in the #lang
line. That allows the module to use at-expressions, which, in this
case, I use for writing the first regexp, since they allow me to elide
a layer of escape syntax.

- 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] Code critique (of naive code) would be very appreciated

2017-06-21 Thread Jon Zeppieri
Hi Glenn,

This is pretty good! I added some remarks below:

On Wed, Jun 21, 2017 at 3:48 PM, Glenn Hoetker  wrote:
>
> ;;;
> #lang racket
>
> (define in (open-input-file "/Users/me/BibDeskPapers/oldBib.bib"))
> (define out (open-output-file "/Users/me/BibDeskPapers/newBib.bib" #:exists 
> 'replace))
> (define keyword-prefix "\tKeywords = {")
>
> ;; Return a string with only the first word capitalized and all else in lower 
> case
> ;; Courtesy https://groups.google.com/forum/m/#!topic/racket-users/gw8Ivm5HSZQ
> (provide
>  (contract-out
>   [string-upcase-first-word (-> string? string?)]))

If you want your use of `string-upcase-first-word` to be protected by
this contract, then you'll either need to:
- provide it, like you do here, from a *different* module, and require
it in this one, or
- define the function in this module with `define/contract`.

What you're doing:
   (provide (contract-out ...))

... means that other modules that require this one will get the
contract-protected version of the function, but within this module,
the function has no contract. You can read about contract boundaries
here [http://docs.racket-lang.org/guide/contract-boundaries.html].

>
> (define (string-upcase-first-word s)
>   (apply
>string
>(for/list ([c (in-string s)]
>   [i (in-naturals)])
>  (if (= i 0)
>  (char-upcase c)
>  (char-downcase c)
>
> (module+ test
>   (require rackunit)
>   (check-equal? (string-upcase-first-word "") "")
>   (check-equal? (string-upcase-first-word "Cat Dog") "Cat dog")
>   (check-equal? (string-upcase-first-word "cat dog") "Cat dog"))
>
> ;; Main program
> (for ([aLine (in-lines in)])

Racketeers typically use hyphen-delimited identifiers instead of camel
case (though in this particular situation, I think it would be more
common to use `line` instead of either `aLine` or  `a-line`).

>   (cond
> [(string-prefix? aLine "\tKeywords = {") ; Identify Keywords lines
>  (define keywords-as-list (string-split (string-replace aLine "\tKeywords 
> = {" "") ","))
>  (define cleaned-keywords (map (lambda (aString)
>  (string-upcase-first-word
>   (string-trim aString)))
>keywords-as-list))
>  (display keyword-prefix out)
>  (display (string-join cleaned-keywords ", ") out)
>  (display "," out)
>  (newline out)]
> [else (display aLine out) (newline out)]))

Usually, you'd put separate sequential expressions on separate lines.
Since the second expression is just meant to add a newline to the end
of the string you just displayed, you can use `displayln` instead:

  [else (displayln line)]

>
> ;;;

One general piece of advice: abstract your main loop into a procedure
that accepts input and output ports. That will make it much easier to
test.

I gave some thought to how I'd accomplish the same thing and came up
with the following. This version assumes you're going to read the
entire file into memory as a string. Of course, you can substitute
your favorite version of the capitalization procedure:

#lang at-exp racket

;; normalize-keywords: string? -> string?
#lang at-exp racket

(define (normalize-keywords in)
  (regexp-replace*
   @pregexp|{Keywords ?= ?\{\s*([^}]*)\}}|
   in
   (λ (_ s)
 (string-join
  (map capitalize-first (regexp-split #px", *" s))
  ", "

(define (capitalize-first s)
  (cond
[(non-empty-string? s)
 (string-append
  (string-upcase (substring s 0 1))
  (string-downcase (substring s 1)))]
[else
 ""]))

-- 
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] Naive question on how to capitalize only the first word of a string

2017-06-19 Thread Jon Zeppieri
On Mon, Jun 19, 2017 at 8:12 PM, Glenn Hoetker  wrote:
> I'm quite new to Racket/LISP, so I hope this isn't breathtakingly obvious.  
> Can someone please tell me the best way to capitalize just the first word in 
> a multiword string.  So, given the string "it was a dark and stormy night", I 
> would like to get "It was a dark and stormy night". I see functions for 
> turning everything lower case, everything uppercase or capitalizing each 
> word, but nothing in line with what I hope to do.
>
>> (define it "cat dog")
>> (string-titlecase it)
> "Dog Cat"  ; So close, but not quite "Dog cat" as I want.
>
> Many thanks.
>

Yet another option:

#lang racket

(define (cap-first str)
  (match (string->list str)
[(cons x xs)
 (list->string
  (cons (char-upcase x) xs))]
[_
 str]))

-- 
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] Making change in Racket / lazy language question

2017-06-16 Thread Jon Zeppieri
On Fri, Jun 16, 2017 at 5:41 PM, Daniel Prager
 wrote:
>
> But I get a perplexing error if I try to use foldl for added elegance when
> defining twos:
>
> (define (cc x . xs) (foldl sadd (fcoin x) xs))
> (define twos (cc 1 2 5 10 20 50 100 200))
>
> take: expects type  as 1st argument, given: '(1
> . #); other arguments were: 2
>
> What's going on?

The procedure that you use as `foldl`'s first argument expects the
accumulator last, not first, so you'd just need to swap the order of
`sadd`'s arguments.

if you define `sadd` as:

   (define (sadd n xs) (append (take n xs) (map + (list-tail xs n)
(sadd n xs

Then it should work.

- 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] Data contract for non-empty hash?

2017-06-12 Thread Jon Zeppieri
Predicates can be used as contracts, so:

(define (non-empty-hash? x)
  (and (hash? x)
   (not (hash-empty? x

Then you can use `non-empty-hash?` as your contract.



On Mon, Jun 12, 2017 at 3:56 PM, David Storrs  wrote:
> There is a non-empty-listof contract but no non-empty-hashof contract.  Is
> there a way to build one?
>
> --
> 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.

-- 
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] Performance of the Racket reader

2017-06-01 Thread Jon Zeppieri
On Thu, Jun 1, 2017 at 11:07 AM, Jon Zeppieri <zeppi...@gmail.com> wrote:
>
>
>> On Jun 1, 2017, at 10:52 AM, Steve Byan's Lists <steve-l...@byan-roper.org> 
>> wrote:
>>
>> Hi Jon,
>>
>>>> On May 31, 2017, at 6:41 PM, Steve Byan's Lists 
>>>> <steve-l...@byan-roper.org> wrote:
>>>>
>>>> On May 31, 2017, at 6:14 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
>>>>
>>>> So, for example:
>>>>
>>>> (define (map-trace stat%-set in-port)
>>>> (for/fold ([sexp-count 0])
>>>>  ([trace-record (in-port read in)])
>>>>  (+ sexp-count 1)))
>>>>
>>>> (I didn't try this, but I think it's right.)
>>>>
>>>> This way, you don't build up a list or a lazy stream; you just process
>>>> each datum as it's read.
>>>
>>> Thanks, I don't recall why I didn't think of this alternative. I guess I 
>>> was hung up on streams, or else not thinking of s-expressions as lists :-(
>>
>> Alas, it's only a 13% reduction in run-time. About 91K records/second as 
>> opposed to 80K records/second. (I'm running on a system with turbo-boost 
>> enabled today, hence the 80K recs/sec for the stream instead of the 62K I 
>> reported yesterday.)
>>
>> I'll make another try using Neil's approach of formatting the trace records 
>> as a simple list.
>>
>
> If you try the simple list approach, consider using vectors instead of lists. 
> The memory representation is flat, so it should be a bit more efficient, and 
> it's every bit as easy to use match with vectors. (Prefab structs are another 
> possibility.) However, you might just find that nothing will make this 
> general approach fast enough.
>
> By the way, match tends to generate good code, so I wouldn't be too worried 
> about its overhead, unless you're doing something like matching list elements 
> out-of-order.
>

Oh, sorry -- I see that Neil's approach really requires lists instead
of vectors. I'm interested to hear the results of this experiment. I'd
actually expect the `match` approach (without any first-class use of
functions) to be faster, but my picture of Racket's optimization might
be outdated.

-- 
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] Performance of the Racket reader

2017-06-01 Thread Jon Zeppieri


> On Jun 1, 2017, at 10:52 AM, Steve Byan's Lists <steve-l...@byan-roper.org> 
> wrote:
> 
> Hi Jon,
> 
>>> On May 31, 2017, at 6:41 PM, Steve Byan's Lists <steve-l...@byan-roper.org> 
>>> wrote:
>>> 
>>> On May 31, 2017, at 6:14 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
>>> 
>>> So, for example:
>>> 
>>> (define (map-trace stat%-set in-port)
>>> (for/fold ([sexp-count 0])
>>>  ([trace-record (in-port read in)])
>>>  (+ sexp-count 1)))
>>> 
>>> (I didn't try this, but I think it's right.)
>>> 
>>> This way, you don't build up a list or a lazy stream; you just process
>>> each datum as it's read.
>> 
>> Thanks, I don't recall why I didn't think of this alternative. I guess I was 
>> hung up on streams, or else not thinking of s-expressions as lists :-(
> 
> Alas, it's only a 13% reduction in run-time. About 91K records/second as 
> opposed to 80K records/second. (I'm running on a system with turbo-boost 
> enabled today, hence the 80K recs/sec for the stream instead of the 62K I 
> reported yesterday.)
> 
> I'll make another try using Neil's approach of formatting the trace records 
> as a simple list.
> 

If you try the simple list approach, consider using vectors instead of lists. 
The memory representation is flat, so it should be a bit more efficient, and 
it's every bit as easy to use match with vectors. (Prefab structs are another 
possibility.) However, you might just find that nothing will make this general 
approach fast enough.

By the way, match tends to generate good code, so I wouldn't be too worried 
about its overhead, unless you're doing something like matching list elements 
out-of-order.

> Best regards
> -Steve
> 
> --  
> Steve Byan
> steveb...@me.com
> Littleton, MA
> 
> 
> 

-- 
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] Performance of the Racket reader

2017-05-31 Thread Jon Zeppieri
On Wed, May 31, 2017 at 10:05 PM, Steve Byan's Lists
 wrote:
>
> I did consider using an association list representation for the attributes, 
> but I'm depending on s-expression pattern matching for parsing the records. 
> It's wonderfully convenient for this. I'm under the impression that `match` 
> requires proper lists as input.

`match` is very flexible. Assuming your pmem_flush lists always have
the same attributes in the same order, you could do:

(match datum
  [`(pmem_flush
 (threadId . ,thread-id)
 (startTime . ,start-time)
 ...)
   < do something with thread-id, start-time, etc. >]
   ...)

If they're not always in the same order, you can use the
`list-no-order` pattern instead of `list`. If you only want to match
some of the pairs, you can do that too:

(match datum
  [(list-no-order pmem_flush (cons 'startTime t) _ ...) t]
  ...)

- 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] Performance of the Racket reader

2017-05-31 Thread Jon Zeppieri
On Wed, May 31, 2017 at 5:54 PM, Steve Byan's Lists
 wrote:
> Hi Mathias,
>
> Thanks for taking a look.
>
>> On May 31, 2017, at 4:13 PM, Matthias Felleisen  wrote:
>>
>>
>> Can you explain why you create a lazy stream instead of a plain list?
>
> The current size of a short binary trace file is about 10 GB, and I want to 
> scale to traces many hundreds of megabytes in size. The expanded s-expression 
> form is about 10 times larger, so keeping the whole list in memory could 
> require up to many terabytes of memory.
>
> Aside from just handling large traces, I also parallelize the problem by 
> running analysis processes on different trace files concurrently. So the 
> amount of memory required for the parallel computation would be about 32 
> times the memory needed for a single trace analysis process.
>
> So, I don't want to try to fit all the records in memory at once. I thought 
> that the lazy stream would accomplish this --- am I wrong?

You're right, but using a lazy stream will still consume more than
just using `read` within the loop that actually processes the data.
So, for example:

(define (map-trace stat%-set in-port)
  (for/fold ([sexp-count 0])
([trace-record (in-port read in)])
(+ sexp-count 1)))

(I didn't try this, but I think it's right.)

This way, you don't build up a list or a lazy stream; you just process
each datum as it's read.

-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] Html to text, how to obtain a rough preview

2017-05-30 Thread Jon Zeppieri
((sxpath '(// *text*)) doc)

should return all (and only) the text nodes in doc. I'm not so
familiar with the sxml-xexp compatibility stuff, so I don't know if
you can use an xexp here or if you really need an sxml document.

On Tue, May 30, 2017 at 7:08 AM, Erich Rast  wrote:
> Hi all,
>
> I need a function to provide a rough textual preview (without
> formatting except newlines) of the content of a web page.
>
> So far I'm using this:
>
> (require net/url
>  html-parsing
>  sxml)
>
> (provide fetch fetch-string-content)
>
> (define (fetch url)
>   (call/input-url url
>   get-pure-port
>   port->string))
>
> (define (fetch-string-content url)
>   (sxml:text ((sxpath '(html body)) (html->xexp (fetch url)
>
> The sxpath correctly returns the body sexp, but fetch-string-content
> still only returns an empty string or a bunch of "\n\n\n".
>
> I guess the problem is that sxml:text only returns what is immediately
> below the element, and that's not what I want. There are all kinds of
> unknown div and span tags in web pages. I'm looking for a way to get
> a simplified version of the textual content of the html body. If I was
> on Linux only I'd use "lynx -dump -nolist" in a subprocess, but it needs
> to be cross-platform.
>
> Is there a sxml trick to achieve that? It doesn't need to be perfect.
>
> Best,
>
> Erich
>
> --
> 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.

-- 
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] immutable hash table performance

2017-05-25 Thread Jon Zeppieri
On Thu, May 25, 2017 at 6:16 PM, 'John Clements' via Racket Users
 wrote:
> Following up on a discussion I had with another teacher here, I decided to 
> briefly investigate the running time of insertion and deletion on mutable vs 
> immutable hash tables. I was a bit disappointed to find that it turns out 
> that insertion really doesn’t look very constant-time for insertion… or for 
> lookup, actually. I drew some pictures: tell me what you think!
>
> https://www.brinckerhoff.org/blog/2017/05/25/hash-table-timings/
>
> John

Immutable hash operations are logarithmic, not constant time.

-- 
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: Proper non-tail recursion?

2017-04-27 Thread Jon Zeppieri
On Thu, Apr 27, 2017 at 8:13 PM, Justin Zamora <jus...@zamora.com> wrote:
> On Thu, Apr 27, 2017 at 8:06 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
>>
>> OCaml does handle tail calls properly. But proper tails calls are not
>> the subject of this discussion. The original post was explicitly about
>> non-tail calls and how, in Racket, you cannot exhaust the stack
>> without exhausting all of the memory available to the program.
>> (Whereas in OCaml you can, because it uses a fixed-size stack.)
>
>
> How common is it to have a fixed-size stack? I thought it was normal
> practice for the heap and stack to be on opposite ends of memory and to grow
> towards each other, so that either can use all available memory.
>
> Justin

It's the norm, and it's typically enforced by the OS. (Of course, you
could ignore the system's stack and build your own stack in the heap,
but you will pay a performance price.) That's why the technique that
Matthias described involves detecting overflows and copying the
current stack to the heap.

-- 
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: Proper non-tail recursion?

2017-04-27 Thread Jon Zeppieri
On Thu, Apr 27, 2017 at 8:05 PM, Hendrik Boom <hend...@topoi.pooq.com> wrote:
> On Thu, Apr 27, 2017 at 07:14:15PM -0400, Jon Zeppieri wrote:
>> On Thu, Apr 27, 2017 at 7:10 PM, Raoul Duke <rao...@gmail.com> wrote:
>> > i should think any "real" fp would support it. where real is a bijection
>> > with having such support.  well, at least necessary if not sufficient.
>>
>> That would be a rather contentious claim, as it rules out OCaml, for example.
>
> I really thought OCaml did tail-recursion properly.  Its tutorial
> literature goes th some trouble to explain that it's OK to recurse
> tailfully.  What is the truth here?
>

OCaml does handle tail calls properly. But proper tails calls are not
the subject of this discussion. The original post was explicitly about
non-tail calls and how, in Racket, you cannot exhaust the stack
without exhausting all of the memory available to the program.
(Whereas in OCaml you can, because it uses a fixed-size stack.)

-- 
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: Proper non-tail recursion?

2017-04-27 Thread Jon Zeppieri
On Thu, Apr 27, 2017 at 7:10 PM, Raoul Duke  wrote:
> i should think any "real" fp would support it. where real is a bijection
> with having such support.  well, at least necessary if not sufficient.

That would be a rather contentious claim, as it rules out OCaml, for example.

-- 
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] Best way to write run-once-and-cache functions?

2017-04-26 Thread Jon Zeppieri
On Wed, Apr 26, 2017 at 12:48 PM, David Storrs <david.sto...@gmail.com> wrote:
>
>
> On Wed, Apr 26, 2017 at 12:21 AM, Jon Zeppieri <zeppi...@gmail.com> wrote:
>>
>> I don't know that there's a right way, but if your functions are
>> nullary, then promises are a decent fit:
>>
>> (define conf
>>   (delay
>> (with-input-from-file ...)))
>>
>> Then just (force conf) whenever you want the value.
>
>
> Yeah, that works well.  Thanks!
>
> Any thoughts on how to do it for non-nullary functions?
>>

The more complicated your function signatures get, the more worthwhile
it will be to use the memoize package. But for, say, unary functions
you can easily use a hash table:

#lang racket

(define read-conf
  (let ([h (make-hash)])
(λ (arg)
  (hash-ref! h
 arg
 (thunk ...)

You can extend this to multiple arguments by using lists as keys, if
you want. Of course, you need to make sure that `equal?` is usefully
defined on your argument types.

-- 
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] Best way to write run-once-and-cache functions?

2017-04-25 Thread Jon Zeppieri
I don't know that there's a right way, but if your functions are
nullary, then promises are a decent fit:

(define conf
  (delay
(with-input-from-file ...)))

Then just (force conf) whenever you want the value.



On Wed, Apr 26, 2017 at 12:12 AM, David Storrs  wrote:
> Reading configuration files is a good example of a run-once function.  It's
> effectively self-memoizing -- it should run once, cache its result, and on
> future calls just return the cached value.  I could pull in
> https://docs.racket-lang.org/memoize/index.html or
> http://docs.racket-lang.org/mischief@mischief/memoize.html to do that, but
> adding an extra module to the project just for one or two functions feels
> pretty heavy. (Also, memoizing is overkill if the functions are thunks.)  Is
> there a simple way to do this in pure Racket?
>
> In Perl I would do something like this (for simplicity I'm ignoring encoding
> and assuming that the config file is JSON):
>
> use JSON;
> sub read_conf {
>   state $conf = do {
> local $/;
> open my $fh, "<", "db.conf" or die "failed to open config: $!";
> from_json( <$fh> )
>   };
>   $conf
> }
>
>
> I could do this in Racket using set!, but that's not very Rackety:
>
> (require json)
> (define conf #f)
> (define (read-conf)
>(or conf
>  (begin
>(set! conf (with-input-from-file "db.conf" (thunk (read-json
>conf)))
>
>
> I could do it with a parameter but that's only sweeping the above ugliness
> under the rug:
>
> (define conf (make-parameter #f))
> (define (read-conf)
>(or (conf)
>  (begin
>(conf (with-input-from-file "db.conf" (thunk (read-json
>(conf
>
> What is the right way?
>
> --
> 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.

-- 
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] Proper non-tail recursion?

2017-04-25 Thread Jon Zeppieri
On Tue, Apr 25, 2017 at 6:37 PM, brendan  wrote:
> Scheme implementations are required to have proper tail recursion. Racket 
> goes further and lets the programmer make recursive calls from any position 
> without fear because, to paraphrase Dr. Flatt, it's the 21st century and 
> stack overflows should not be a thing. My questions are: Is there a name for 
> this feature? And do any other major languages or implementations have it? 
> Thanks.

I don't know if there's one particular term for this. A resizable (or
growable) call stack, maybe?

It's very different from proper tail calls, though, because a non-tail
call still accumulates space, and you can still run out of space. It's
just that many language implementations use a fixed-size stack,
whereas Racket will increase the size of the stack at runtime. I'm not
sure what other language implementations do this.

-- 
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] Reporting exceptions as though they came from the caller

2017-03-31 Thread Jon Zeppieri
On Fri, Mar 31, 2017 at 4:00 PM, David Storrs  wrote:
> Imagine I have the following trivial module (ignore that things are defined
> out of sequence for clarity):
>
> #lang racket
>
> (define (foo arg)
> (_baz arg)  ; do some checking, raise an exception if there's a problem
> ...do stuff...
> )
>
> (define (bar arg)
> (_baz arg)  ; do some checking, raise an exception if there's a problem
> ...do stuff)
>
> (define (_baz arg)  ; internal helper function
> (when (equal? arg "bad value")
> (raise-arguments-error '_baz "got a bad value" "val" val))) ;; <===
> report is from _baz, not foo or bar
>
> (provide foo bar)
>
>
> In Perl I can use caller() [1] to access the stack so that I can have _baz
> report errors as though the error were coming from 'foo' or 'bar' as
> appropriate -- which is what the user expects to see, since their code
> called 'foo' or 'bar', not '_baz'.  (Even better, I could report as though
> the error were coming from the *caller* of foo / bar, which is the user's
> actual code and the real source of the problem.) How can I do the same in
> Racket?  I see the errortrace library, but that says "don't install this
> into a module and expect it to work."
>
> I could pass the name down, of course, but that's clumsy.  I could also
> create a parameter and set it every time I call the helper function that
> needs it, but that's even more clumsy / action-at-a-distance-y and easy to
> forget.  What's the right way?
>
>
> [1] https://perldoc.perl.org/functions/caller.html
>


Depending on your exact situation, you may be able to get the contract
system to do the work for you. A non-trivial example from actual code:

In the Gregor library, there are a number of constructors that accept
year, month, and day arguments. All of them need to ensure that the
combination refers to an actual day. Instead of having each use code
like:

 (if (date-exists? year month day)
   (something-useful)
   (raise-bad-date ...))

those functions all have contracts like:

```
[date (->i ([year exact-integer?])
   ([month (integer-in 1 12)]
[day (year month) (day-of-month/c year month)])
   [d date?])]
```

The most interesting argument contract there is `day-of-month/c`,
which checks the `day` argument, but depends on both `year` and
`month`, as well.

`day-of-month/c` is defined like this:

```
(define (day-of-month/c y m)
  (integer-in 1 (days-in-month y m)))
```
Where `days-in-month` does what you would expect.

-- 
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 to `read-char` from port using `latin-1` encoding?

2017-03-31 Thread Jon Zeppieri
Try using "iso-8859-1" as the name of the encoding, instead of "latin-1." -J


On Fri, Mar 31, 2017 at 3:55 PM, Matthew Butterick  wrote:
> IIUC when `read-char` reads from a port it assumes the port uses UTF-8
> encoding. [1]
>
> (My Racketuition suggests there might be a parameter called
> `current-port-encoding` that controls what encoding is applied to the port,
> but apparently not.)
>
> So instead, one must convert the port explicitly. OK, this seems to work:
>
> (open-input-string (bytes->string/latin-1 (port->bytes port)))
>
> The problem is that I'm reading all the bytes first, which defeats the
> port-ishness of the operation.
>
> But if I try the promising-sounding `reencode-input-port`:
>
> (reencode-input-port port "latin-1")
>
> This doesn't work, because it relies on `bytes-open-converter`, which
> apparently doesn't know about `latin-1` encoding (a teeny bit surprising
> since other racket/base functions deal with this encoding)
>
> Hence the question: is there a smarter way to read characters from a
> `latin-1` encoded port?
>
>
> [1] http://docs.racket-lang.org/reference/encodings.html?q=encoding
>
> --
> 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.

-- 
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 to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Jon Zeppieri
Oh, never mind. I see what you mean.

On Tue, Mar 21, 2017 at 8:42 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
> Did you try a using a bytea field?
>
> On Tue, Mar 21, 2017 at 8:36 PM, Marc Kaufmann
> <marc.kaufman...@gmail.com> wrote:
>> Thanks. But I have to turn it into a string before storing it in the
>> database; when I tried to store a serialized list in it (in a VARCHAR
>> field), it complained that it expected a string. That's where all the
>> trouble came from. The trouble I had was parsing the string back into the
>> serialized form, which 'with-input-from-string does (because, I presume, it
>> treats the contents of the string as the input, rather than the string
>> itself).
>>
>> Of course, if there is a way to store serialized data directly in the
>> database, that would be great - but -- except for arrays in a Postgre
>> database -- that doesn't seem to be the case.
>>
>>
>>
>> On Tue, Mar 21, 2017 at 8:04 PM, Philip McGrath <phi...@philipmcgrath.com>
>> wrote:
>>>
>>> When you use:
>>> (write (~a (serialize '((0 1) (1 0 out)
>>> you are first turning the result of deserialize into a string, then
>>> writing the string, so read will produce a string.
>>>
>>> Your example will work correctly if you drop the ~a and just use:
>>> (write (serialize '((0 1) (1 0))) out)
>>>
>>> If that's less than totally clear, for illustrative purposes, consider the
>>> following:
>>> > (serialize '((0 1) (1 0)))
>>> '((3) 0 () 0 () () (q (0 1) (1 0)))
>>> > (~a '((3) 0 () 0 () () (q (0 1) (1 0
>>> "((3) 0 () 0 () () (q (0 1) (1 0)))"
>>> > (with-output-to-string
>>>(λ () (write "((3) 0 () 0 () () (q (0 1) (1 0)))")))
>>> "\"((3) 0 () 0 () () (q (0 1) (1 0)))\""
>>> > (with-input-from-string "\"((3) 0 () 0 () () (q (0 1) (1 0)))\""
>>>   read)
>>> "((3) 0 () 0 () () (q (0 1) (1 0)))"
>>> > (with-output-to-string
>>>(λ () (write '((3) 0 () 0 () () (q (0 1) (1 0))
>>> "((3) 0 () 0 () () (q (0 1) (1 0)))"
>>> > (with-input-from-string "((3) 0 () 0 () () (q (0 1) (1 0)))"
>>>   read)
>>> '((3) 0 () 0 () () (q (0 1) (1 0)))
>>> > (deserialize '((3) 0 () 0 () () (q (0 1) (1 0
>>> '((0 1) (1 0))
>>>
>>> On Tue, Mar 21, 2017 at 6:53 PM Marc Kaufmann <marc.kaufman...@gmail.com>
>>> wrote:
>>>>
>>>> Regarding not using deserialize directly: I may be using deserialize in
>>>> the wrong way, but the following doesn't work (and I had tried that before
>>>> posting):
>>>>
>>>> > (define-values (in out) (make-pipe))
>>>> > (write (~a (serialize '((0 1) (1 0)
>>>> "((3) 0 () 0 () () (q (0 1) (1 0)))"
>>>> > (write (~a (serialize '((0 1) (1 0 out)
>>>> > (deserialize (read in))
>>>> ; car: contract violation
>>>> ;   expected: pair?
>>>> ;   given: "((3) 0 () 0 () () (q (0 1) (1 0)))"
>>>> ; [,bt for context]
>>>>
>>>> 'read simply returns a string. On the other hand, using Philip's
>>>> suggestion works (although I can't say I fully understand the subtleties
>>>> involved):
>>>>
>>>> > (define serialized-string (~a (serialize '((0 1) (1 0)
>>>> > (with-input-from-string serialized-string (lambda () (deserialize
>>>> > (read
>>>> '((0 1) (1 0))
>>>>
>>>> Regarding pg-array, I thought (from the docs) that it allowed for
>>>> multi-dimensional arrays, but since I might need a similar functionality 
>>>> for
>>>> structs and the like, I thought that I should find another solution.
>>>>
>>>> Thanks everyone for the quick response.
>>>>
>>>> Cheers,
>>>>
>>>> Marc
>>>>
>>>>
>>>> On Tue, Mar 21, 2017 at 5:58 PM, George Neuner <gneun...@comcast.net>
>>>> wrote:
>>>>>
>>>>> On 3/21/2017 5:48 PM, Jon Zeppieri wrote:
>>>>>
>>>>> Ah, except apparently `pg-array` only supports arrays with dimension
>>>>> 1. So... that won't help.
>>>>>
>>>>>
>>>>> I *think* Ryan Culpepper fixed that a long time ago ... though the docs
>>>>> may never 

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Jon Zeppieri
On Tue, Mar 21, 2017 at 5:44 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
> However, postgres (if that's what you're using)
> has multidimensional arrays as a native type, so you could use those
> [https://www.postgresql.org/docs/current/static/arrays.html]. The
> Racket db package has a `pg-array` struct with conversion to/from
> lists to help you.
>

Ah, except apparently `pg-array` only supports arrays with dimension
1. So... that won't help.

-- 
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 to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Jon Zeppieri
On Tue, Mar 21, 2017 at 5:34 PM, Marc Kaufmann
 wrote:
> Hi,
>
> I want to store matrices of the following form (but larger) in a database:
>
> (define m '((0 1) (1 0)))
>
> Currently I manage to store them by turning them into strings first via:
>
> (~a (serialize m)); Or just drop the serialize, but I figured I might benefit 
> from it later.
>
> The problem is that I can only get a string out of the database. Obviously I 
> could write a parser for this, but it feels a little odd having to write one 
> for such a simple, and probably common, task.
>
> The question I have is whether there is a common best practice for storing 
> such things in a database, or whether I should write a parser? And if I 
> should write a parser, I presume I should use either Parsack or Megaparsack?

Depends on your needs. However, postgres (if that's what you're using)
has multidimensional arrays as a native type, so you could use those
[https://www.postgresql.org/docs/current/static/arrays.html]. The
Racket db package has a `pg-array` struct with conversion to/from
lists to help you.

If you're not using postgres and you don't actually need to query
against the data, just store and retrieve it, then
serialize/deserialize is fine.

-- 
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] Why doesn't this maxval function correctly return the maximum value in the list

2017-02-12 Thread Jon Zeppieri
On Sun, Feb 12, 2017 at 3:00 PM, Angus  wrote:
> I am a beginner Racket developer by the way.
>
> Here is my maxval function which is supposed to take a list and return the 
> largest integer in the list.
>
>  (define (maxval lst)
>(define (aux lst max)
>  (cond [(null? lst)  max]
>[(car lst) > max (aux (cdr lst) (car lst))]

Right here ^^^ you're trying to use `>` as an infix operator, but
that's not how Racket syntax works. What you want is:

 [(> (car lst) max) <...>]

The way you wrote it, it means: "If the first element of `lst` isn't
#f, then evaluate `>` for side-effects (which does nothing), then
evaluate `max` for side-effects (which does nothing), then return the
value of `(aux (cdr lst) (car lst))`."


>[#t (aux (cdr lst) max)]))

Preferred Racket style is to use `else` here instead of `#t`.

- 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] Basic macro question

2017-02-05 Thread Jon Zeppieri
On Sun, Feb 5, 2017 at 10:12 PM,   wrote:
> Ahh... datum->syntax, I thought I had seen something like this before. It is 
> treating "a", or a's form, as the scope for the new ids essentially, but I 
> can pick standard names. This just presupposes I only care to use my "a" 
> macro once in any given scope. Does this really make it an unhygenic solution?

If you're planning to use the identifiers outside the macro, then yes.
The idea is that at an identifier's use site, you should only see
bindings that are lexically apparent. So, for example, if you had:

(define x 20)
(a)
x

You should expect `x` on the third line to evaluate to 20, because
that's the lexically apparent definition of x. But non-hygienic macros
can break that rule.

- 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] Basic macro question

2017-02-05 Thread Jon Zeppieri
On Sun, Feb 5, 2017 at 9:41 PM,   wrote:
> I must be missing something simple here.
>
> 229> (define-syntax a (lambda (stx) (syntax-parse stx [(a) #`(begin (define x 
> 97) (define y 98) (define z 99))])))
> 230>(a)
> 231>y
> 232; y:undefined;
> 233; cannot reference undefined identifier
> 234; [,bt for context]
>
> If the macro is given these ids, like (a x y z), then it will work, but can't 
> I also pick standard names like this in advance, or is that somehow 
> fundamentally "unhygienic"?

Yep, it's a matter of hygiene.

> Perhaps I have to generate the names in a place visible to both the 
> definition and use or something...

Not sure exactly what you have in mind. At any rate, you can provide
the identifiers to the macro, like you mentioned, or you can make a
non-hygienic macro.

-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] Beginners question: implementing existing generics for existing structs

2017-01-31 Thread Jon Zeppieri
On Tue, Jan 31, 2017 at 4:49 PM, Ronie Uliana  wrote:
> Let's assume I have a struct that is not mine (like ddict 
> [https://pkgn.racket-lang.org/package/ddict], or some of pfds 
> [https://pkgn.racket-lang.org/package/pfds]). I'd like to implement generics 
> for them that also are not mine :p (like data/collection from Alexis King).
>
> 1 - Is it possible?
> 2 - How do I do that?
>

Short of sending a pull request to the package maintainer, I don't
think it's possible, and it seems like any attempt to make that work
would invite modularity problems similar to the instance coherence
problem for type classes. Consider two modules that implement
gen:serializable for the same struct type in incompatible ways. -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] Thread and filesystem watching

2017-01-25 Thread Jon Zeppieri
On Wed, Jan 25, 2017 at 8:03 PM, Matthew Flatt  wrote:
>
> The `handle-evt` constructor does that.
>
> For example, this loop will print "one" or "two" pseudorandomly, depending on 
> whether the first or second semaphore is chosen:
>
>  (let loop ()
>(define e1
> (handle-evt (make-semaphore 1)
> (lambda (v)
>   (printf "one\n")
>   (loop
>(define e2
> (handle-evt (make-semaphore 1)
> (lambda (v)
>   (printf "two\n")
>   (loop
>(sync e1 e2))

Oh, that's a lot more convenient than I realized. Guess I never gave
enough thought to the value of the handler being called in tail
position w.r.t. the sync. -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] Thread and filesystem watching

2017-01-25 Thread Jon Zeppieri
On Wed, Jan 25, 2017 at 7:34 PM, David Storrs  wrote:
>
>
> After trying this out I see there's a problem:  if you apply sync to all of 
> them simultaneously there is no way to distinguish which directory it was 
> that changed.  By spawning a separate thread for each one I can close over 
> the relevant directory.  Unless I'm missing something?
>
> I wish there were a way to encode information into the change event at 
> creation time.
>
>

You can use `wrap-evt` or `handle-evt` for this, I think, though it
does seem like it should be more convenient:

   (handle-evt (filesystem-change-evt path) (λ (_) path))

-- 
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] Thread and filesystem watching

2017-01-24 Thread Jon Zeppieri
Hi David,

On Tue, Jan 24, 2017 at 6:52 PM, David Storrs 
wrote:

> [snip]
>
> - When I create the 'monitor this' event, I will need to wrap the sync in
>> a thread since (sync) is synchronous.
>
>
>
> If I understand you correctly, you're considering creating a separate
thread for each directory that you monitor. You could do that, but I'd
suggest this instead:
- build a list of `filesystem-change-evt`s
- create a single thread, and in it monitor all of them at once with
`(apply sync list-of-evts)`

- 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] Client side web applications in Racket

2017-01-22 Thread Jon Zeppieri


> On Jan 22, 2017, at 4:33 PM, Philip McGrath  wrote:
> 
> My understanding is that implementation is still lagging, but I believe ES6 
> specifies proper tail calls, yes?
> 
> -Philip

Yep. Right now (among browsers) I think only Safari ships with it. -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] contracts: the blame name game

2017-01-03 Thread Jon Zeppieri
Thanks Robby! -J


On Tue, Jan 3, 2017 at 8:58 AM, Robby Findler <ro...@eecs.northwestern.edu>
wrote:

> There may be a way to do this without it, but I've just pushed a
> change to define-module-boundary-contract that lets you specify the
> name that you want in the error message.
>
> Also, if you can use a `let`, that's probably better than
> procedure-rename, eg:
>
> (define make-bar
>   (let ([bar (λ (x [y 1] [z 1])
>(bar x y z))])
> bar))
>
> (It won't matter unless you call `bar` a lot.)
>
> Robby
>
>
> On Mon, Jan 2, 2017 at 1:25 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
> > Over time I've run into a number of problems trying to provide custom
> struct
> > constructors and match expanders under the same name, while also
> attaching
> > module-level contracts to the constructors. I've figured out most of the
> > issues (I think), but one remains. Here's an example:
> >
> > ===
> > #lang racket/base
> >
> > (module foo racket/base
> >   (require racket/contract
> >racket/match
> >(for-syntax racket/base
> >syntax/transformer))
> >
> >   (struct bar (x y z))
> >
> >   (define make-bar
> > (procedure-rename
> >  (λ (x [y 1] [z 1])
> >(bar x y z))
> >  'bar))
> >
> >   (define-module-boundary-contract
> > make-bar*
> > make-bar
> > (->i ([x exact-integer?])
> >  ([y (integer-in 0 200)]
> >   [z (x y) (integer-in x y)])
> >  [result bar?]))
> >
> >   (define-match-expander make-bar**
> > (syntax-rules ()
> >   [(_ x y z) (bar x y z)])
> > (make-variable-like-transformer #'make-bar*))
> >
> >   (provide (rename-out [make-bar** bar])))
> >
> >
> > (require 'foo)
> >
> > (bar "hello")
> > ===
> >
> > The submodule here provides the name `bar` which doubles as a custom
> > constructor and a match-expander. And it works fine. The constructor's
> > contract has the right boundary, too. However, the contract violation
> uses
> > the wrong name for the constructor:
> >
> > ../../Applications/Racket
> > v6.7/collects/racket/contract/private/blame.rkt:159:0: make-bar*:
> contract
> > violation
> >   expected: exact-integer?
> >   given: "hello"
> >   in: the x argument of
> >   (->i
> >((x exact-integer?))
> >((y (integer-in 0 200))
> > (z (x y) (integer-in x y)))
> >(result bar?))
> >   contract from: (anonymous-module foo)
> >   blaming: anonymous-module
> >(assuming the contract is correct)
> >   at: unsaved-editor:17.2
> >
> > It's calling the procedure `make-bar*`, which is the internal name,
> instead
> > of `bar`, the public name. Is there a way to get it to use the right
> name?
> >
> > I could name the struct type itself something other than `bar`, which
> would
> > free up that name to be used internally. I've taken that approach in the
> > past, in fact, but there are a number of places where I need to be
> vigilant
> > about names crossing the public/private boundary (notice the use of
> > `procedure-rename` in the above example; without it, `bar` will evaluate
> --
> > in a public context -- to a procedure named `make-bar`, which is
> awkward),
> > and so starting with the public names seems to minimize the number of
> > problems.
> >
> > Any thoughts?
> >
> > - 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.
>

-- 
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] contracts: the blame name game

2017-01-02 Thread Jon Zeppieri
Over time I've run into a number of problems trying to provide custom
struct constructors and match expanders under the same name, while also
attaching module-level contracts to the constructors. I've figured out most
of the issues (I think), but one remains. Here's an example:

===
#lang racket/base

(module foo racket/base
  (require racket/contract
   racket/match
   (for-syntax racket/base
   syntax/transformer))

  (struct bar (x y z))

  (define make-bar
(procedure-rename
 (λ (x [y 1] [z 1])
   (bar x y z))
 'bar))

  (define-module-boundary-contract
make-bar*
make-bar
(->i ([x exact-integer?])
 ([y (integer-in 0 200)]
  [z (x y) (integer-in x y)])
 [result bar?]))

  (define-match-expander make-bar**
(syntax-rules ()
  [(_ x y z) (bar x y z)])
(make-variable-like-transformer #'make-bar*))

  (provide (rename-out [make-bar** bar])))


(require 'foo)

(bar "hello")
===

The submodule here provides the name `bar` which doubles as a custom
constructor and a match-expander. And it works fine. The constructor's
contract has the right boundary, too. However, the contract violation uses
the wrong name for the constructor:

../../Applications/Racket
v6.7/collects/racket/contract/private/blame.rkt:159:0: make-bar*: contract
violation
  expected: exact-integer?
  given: "hello"
  in: the x argument of
  (->i
   ((x exact-integer?))
   ((y (integer-in 0 200))
(z (x y) (integer-in x y)))
   (result bar?))
  contract from: (anonymous-module foo)
  blaming: anonymous-module
   (assuming the contract is correct)
  at: unsaved-editor:17.2

It's calling the procedure `make-bar*`, which is the internal name, instead
of `bar`, the public name. Is there a way to get it to use the right name?

I could name the struct type itself something other than `bar`, which would
free up that name to be used internally. I've taken that approach in the
past, in fact, but there are a number of places where I need to be vigilant
about names crossing the public/private boundary (notice the use of
`procedure-rename` in the above example; without it, `bar` will evaluate --
in a public context -- to a procedure named `make-bar`, which is awkward),
and so starting with the public names seems to minimize the number of
problems.

Any thoughts?

- 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] Cleanest way to locate contiguous sequences? (as part of reuniting segments of a file)

2016-12-02 Thread Jon Zeppieri
You could use an interval tree instead of a list. Before inserting into it,
you could check to see if your current chunk number is contiguous with an
existing interval in the tree. If so, merge the chunks and expand the
existing interval. Otherwise, insert an interval of size 1 into the tree.

Stephen Chang's ftree package might be useful here.

- Jon



On Fri, Dec 2, 2016 at 2:39 PM, David Storrs  wrote:

> This is a more business-logic as opposed to syntax/technique question than
> usually shows up on this list, but hopefully folks won't mind.
>
> I started off to ask "what's the best way to find contiguous sequences of
> numbers in a list?" and then realized that maybe I should answer the "What
> are you trying to achieve?" question first.
>
> Short version:
> Tactical problem:  Given a list of sorted numbers, how best to identify
> contiguous sequences within the list?
> Strategic problem:   How best to put a chunked-up file back together given
> a (possibly incomplete) set of chunks and the index number of those chunks?
>
> Long version:
> I have a file that's been broken up into chunks of roughly standard size
> and I want to put the file back together.  I have the chunk number for each
> chunk so I know what order they should be concatenated in.  I may not have
> all the chunks, but I don't want to wait for all of them to arrive before
> starting the assembly, so I'll need to be able to be able to generate
> intermediate products and add to them later when the assembly process is
> re-run.
>
> My database has filepath and chunk-number data for all chunks (even the
> ones that haven't arrived yet; the filepaths are predictable), so I know
> where the chunks will be and what order to assemble them in.
>
> My first thought is to get the sorted list of chunk numbers for all the
> chunks that I currently have, locate contiguous sub-sequences, and assemble
> those sub sequences, then assemble the sub-sequences once they become
> contiguous.  Something like this:
>
> Available chunk nums:  '(1 2 3 5 7 200 201 202 203)
>
> Group them by contiguous:  '( (1 2 3) (5) (7) (200 201 202 203))
>
> Generate superchunks:  1-3, 200-203
>
> Later...
>
> Available chunk nums:  '(1-3 4 5 7 190 193 200-203)
>
> Group them by contiguous:  '( (1-3 4 5) (7) (190) (193) (200-203))
>
> Merge 4 and 5 into 1-3, rename 1-3 as 1-5.
>
> ...etc
>
> I realized I don't actually know a simple way to identify contiguous
> sub-sequences.  I came up with the following, but it feels clumsy.
>
> (define-values (n final)
>   (for/fold ((prev (car nums))
>  (acc '())
>  )
> ((n (cdr nums)))
> (values n
> (if (= n (add1 prev))
>(cons n acc)
>(begin
>   (set! result (cons (reverse acc) result))
>   (list n
> ))
> (cons (reverse final) result)
>
> Given this:  '(1 2 3 5 7 200 201 202 203)
> It yields this: '((200 201 202 203) (7) (5) (2 3))
>
> Which is fine -- I don't care about the order of the sublists within the
> overall list, as long as each sublist is itself sorted ascending.
>
> Does anyone have any advice to offer, on either the tactical or strategic
> problem?
>
> --
> 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.
>

-- 
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] Very beginner Student who needs Help!

2016-11-27 Thread Jon Zeppieri
Well, okay, first your program needs to admit the possibility of an empty list. 
But once it does, see my previous message.

> On Nov 27, 2016, at 3:45 PM, Ben Ghanem Anis  wrote:
> 
> Hey guys,
> I need some help ..
> I need to write two procedures .. first one should be able to insert a real 
> number in the right position in a list (that is by default sorted ascending) 
> made of pairs (make-pair), also i need to use the procedure to write another 
> one that is able to sort in an ascending way a whole list of real numbers.
> I already did the first step(see included shot) .. but i'm really stuck
> Help!
> 
> -- 
> 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.
> 

-- 
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] Very beginner Student who needs Help!

2016-11-27 Thread Jon Zeppieri
Okay, it might be more obvious how to approach the second procedure if we first 
 consider a missing case in your first. What happens if you try to insert a 
real into an empty list, using your procedure? 

> On Nov 27, 2016, at 3:45 PM, Ben Ghanem Anis  wrote:
> 
> Hey guys,
> I need some help ..
> I need to write two procedures .. first one should be able to insert a real 
> number in the right position in a list (that is by default sorted ascending) 
> made of pairs (make-pair), also i need to use the procedure to write another 
> one that is able to sort in an ascending way a whole list of real numbers.
> I already did the first step(see included shot) .. but i'm really stuck
> Help!
> 
> -- 
> 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.
> 

-- 
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] find-seconds daylight saving

2016-11-10 Thread Jon Zeppieri
On Thu, Nov 10, 2016 at 10:52 AM, Jon Zeppieri <zeppi...@gmail.com> wrote:

>
>
> On Thu, Nov 10, 2016 at 10:45 AM, Jon Zeppieri <zeppi...@gmail.com> wrote:
>
>>
>>
>> On Thu, Nov 10, 2016 at 4:52 AM, George Neuner <gneun...@comcast.net>
>> wrote:
>>
>>>
>>> On 11/9/2016 2:18 AM, Ryan Culpepper wrote:
>>
>>
>>
>>>
>>> Postgresql follows the ISO convention because the SQL standard follow
>>> the ISO convention.  Ask Postgresql for "+5"  ... note I dropped the
>>> separator and minutes (more below) ... and you will get back time in Mumbai
>>> India.  However, Postgresql has to interoperate with the opposing standard
>>> TZ database, so if you ask for "EST" you will get the time for New York
>>> City because Postgresql negated the offset.
>>>
>>
>> I thought Postgres used the same convention as IANA, but it's been a
>> while.
>>
>>
> Ah, I see what's going on here. Right, so the tz database has certain time
> zone names like:
>
> Etc/GMT-4
>
> Where the *name itself* follows the POSIX convention, though it maps to an
> offset that follows the ISO/Olson convention. You can see this if you look
> at the source file "etcetera" in the tz database. You'll see lines like
> this:
>
> ZoneEtc/GMT-14  14  -   +14
> ZoneEtc/GMT-13  13  -   +13
> ZoneEtc/GMT-12  12  -   +12
> ZoneEtc/GMT-11  11  -   +11
>
> You can see that the time zone named Etc/GMT-14 maps to a single offset of
> UTC+14. No joke.
>
>
By the way, these time zones exist specifically *for* POSIX compatibility;
that's why their names follow the POSIX convention. It's not that the tz
database adopted the POSIX convention in general.

Basically: don't use these time zones unless you have a very good reason
to. Or ones like "EST." Stick to the ones that follow the
continent_ish/city naming convention.

- 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] find-seconds daylight saving

2016-11-10 Thread Jon Zeppieri
On Thu, Nov 10, 2016 at 10:45 AM, Jon Zeppieri <zeppi...@gmail.com> wrote:

>
>
> On Thu, Nov 10, 2016 at 4:52 AM, George Neuner <gneun...@comcast.net>
> wrote:
>
>>
>> On 11/9/2016 2:18 AM, Ryan Culpepper wrote:
>
>
>
>>
>> Postgresql follows the ISO convention because the SQL standard follow the
>> ISO convention.  Ask Postgresql for "+5"  ... note I dropped the separator
>> and minutes (more below) ... and you will get back time in Mumbai India.
>> However, Postgresql has to interoperate with the opposing standard TZ
>> database, so if you ask for "EST" you will get the time for New York City
>> because Postgresql negated the offset.
>>
>
> I thought Postgres used the same convention as IANA, but it's been a while.
>
>
Ah, I see what's going on here. Right, so the tz database has certain time
zone names like:

Etc/GMT-4

Where the *name itself* follows the POSIX convention, though it maps to an
offset that follows the ISO/Olson convention. You can see this if you look
at the source file "etcetera" in the tz database. You'll see lines like
this:

ZoneEtc/GMT-14  14  -   +14
ZoneEtc/GMT-13  13  -   +13
ZoneEtc/GMT-12  12  -   +12
ZoneEtc/GMT-11  11  -   +11

You can see that the time zone named Etc/GMT-14 maps to a single offset of
UTC+14. No joke.

- 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] find-seconds daylight saving

2016-11-10 Thread Jon Zeppieri
On Thu, Nov 10, 2016 at 4:52 AM, George Neuner  wrote:

>
> On 11/9/2016 2:18 AM, Ryan Culpepper wrote:
>
>>
>> Another option is to let PostgreSQL do it for you using AT TIME ZONE (or
>> the timezone function):
>>
>>   select ('2016-11-09 01:23:00Z'::timestamptz)
>> at time zone 'us/eastern';
>>   => 2016-11-08 20:23:00
>>
>> But beware that PostgreSQL interprets numerical timezones backwards
>> (sometimes?) (see https://www.postgresql.org/mes
>> sage-id/20151021034109.3017@wrigleys.postgresql.org). I've read that
>> thread and the docs and I still can't make sense of it.
>>
>> Ryan
>>
>
> I know about this one.  The problem is there are two TZ conventions which
> use opposite arithmetic.
>
>  -  ISO-8601 labels east of Greenwich "+" and west "-"
>  -  POSIX labels west of Greenwich "+" and east "-"
>
> The IANA TZ datebase follows POSIX convention.  [Or maybe the reverse: I
> think the database preceded POSIX]


It's the reverse.



> So if you query the TZ database for e.g., "EST", you get back "+05:00" as
> the offset.
>

It's -05:00, but a quick word on the use of "EST," in particular:

The string "EST" is used in two ways in the tz database; it's the name of a
time zone that consistently has a UTC offset of -05:00, and it's also the
symbolic name for the UTC offset of -05:00. These are different things. In
the tz database, "time zone" doesn't mean the same thing as "UTC offset." A
time zone is a collection of rules for determining what the UTC offset
should be at a particular point in time in a particular region.

For example, America/New_York is the canonical name of the time zone that's
used on the Eastern seaboard of the United States. This time zone also has
at least one synonym in the database (viz., US/Eastern). In this time zone,
any point in time will occur at one of several UTC offsets. On my machine,
using the system native zoneinfo database, I have the following UTC offsets
that are used by America/New_York:

(vector
 (tzoffset -14400 #t "EDT")
 (tzoffset -18000 #f "EST")
 (tzoffset -14400 #t "EWT")
 (tzoffset -14400 #t "EPT"))

("EWP" and "EPT," by the way, stand for "Eastern War Time" and "Eastern
Peace Time," respectively.)

(Note that the *time zone* called "EST" is not a synonym for
America/New_York, because the former maps every point in time to UTC-05:00,
whereas the latter does not.)

Oh, and OS X (for... uh, reasons) uses the 32-bit version of the zoneinfo
database. This is only capable of mapping 32-bit POSIX timestamps to UTC
offsets. If you had the 64-bit version instead, there would be an
additional offset in this timezone, namely "LMT."

So, getting back to what I was saying: "EST" is both the name of a *time
zone* that has only one UTC offset (which is also named "EST"), and it's
also the name of a UTC offset.

Now, the symbolic names of UTC offsets are not unique across the tz
database. "EST" (when used as the name of an offset as opposed to the name
of a time zone) is not guaranteed to correspond to -05:00 -- though I
think, at the moment, it might. A better example is "CST." If you live in
the US, you probably think, "Oh, that stands for "Central Standard Time,"
which is UTC-06:00." And it does, but it's also the name of an offset used
in the Asia/Taipei time zone, where it corresponds to UTC+8:00.

What's the point of all of this? If you use the Racket function
`current-date` and you happen to live on the Eastern seaboard of the US,
you might see in the time-zone-name field of the date* struct the string
"EST." That is *not* the name of a time zone in the IANA sense; it's the
name of a UTC offset. And since these names do not uniquely identify UTC
offsets, they're only there as convenient, human-readable abbreviations.
They are not useful for doing work.

In summary:

- Do not use the time-zone-name field of the date* struct for any
computation. Use time-zone-offset instead.
- If you need real time zones, in the IANA sense -- that is, if you don't
already know the local UTC offset of some absolute point in time -- use
Gregor.



>
> Postgresql follows the ISO convention because the SQL standard follow the
> ISO convention.  Ask Postgresql for "+5"  ... note I dropped the separator
> and minutes (more below) ... and you will get back time in Mumbai India.
> However, Postgresql has to interoperate with the opposing standard TZ
> database, so if you ask for "EST" you will get the time for New York City
> because Postgresql negated the offset.
>

I thought Postgres used the same convention as IANA, but it's been a while.



>
> So far, so stupid.
>
>
> But,  SQL defines timezones as "numeric GMT offsets --- using the ISO sign
> convention".   Postgresql closely follows the standard very closely and the
> developers interpret that word "numeric" very literally.   So if you ask
> for "-05:00" - Postgresql sees a string, assumes the user wants the POSIX
> meaning, and negates the offset ... giving you Mumbai.
>
>
> But what about fractional hours? 

Re: [racket-users] find-seconds daylight saving

2016-11-09 Thread Jon Zeppieri
On Tue, Nov 8, 2016 at 11:24 PM, George Neuner <gneun...@comcast.net> wrote:

> Hi Jon,
>
> On 11/8/2016 6:28 PM, Jon Zeppieri wrote:
>
>
> George, these are not correct results. The UTC offset is correct, but the
>> time fields are not -- under the assumption that you're trying to
>> round-trip them unchanged. (But maybe that's not a correct assumption.) At
>> any rate, I think your original example demonstrates a problem with
>> seconds->date on Windows.
>>
>
> Sorry, that was confusing. What I meant to say was: the results are
> correct (given the treatment of the original date fields as UTC and the
> treatment of the resulting seconds as local), but based on your original
> post, I don't think they're the results you were after. But I'm not certain
> of that.
>
> - Jon
>
>
> What I'm trying to do is the following:
>
> - I'm given 2 datetimes as iso8601 -MM-DD HH:MM strings, and a time
> zone offset
> - create UTC datetimes from the strings and tz
> - query a database returning records between the 2 UTC datetimes
>
> OK that was pretty easy.  I believe I need to get [or look up somehow] a
> separate tz for each date string because the range may span both standard
> and daylight time, but at least I can get this far.
>
> Now the hard part:
>
> - I need to turn the UTC datetimes on all the results back into local
> times with the right time zone
>
> This part is driving me nuts.  Nothing seems to work exactly right.
> (seconds->date ... #T) seems to get the numbers right, but not always the
> timezone,
>

Yeah, and this is because you're running into an actual bug that only
affects Windows. I think it's a very simple matter to fix, but since it
only affects Windows, and I don't have a Windows machine, I can't verify
that.



> and in any case it is limited to the local timezone of the machine -
> useless if local *is* UTC, and since I can't specify an arbitrary timezone,
> I can't use it in a server side application.
>

Right -- and this is something that Gregor can help with. If you have UTC
datetimes, you can first translate these from date* instances to Gregor
moments, using 0 as the time zone offset. Then, you can use
`adjust-timezone` to give you a new moment instance that represents the
same point in time but with whatever offset you specify.

That probably sounds a bit overly complicated. The db library doesn't
directly support Gregor, which is why you would need to translate from one
representation to another:

```
(require racket/date
 racket/match
 gregor)

(define (date*->moment/offset d offset)
  (match d
[(date* sec min hr day mon yr _ _ _ off ns _)
 (adjust-timezone (moment yr mon day hr min sec ns #:tz off)
  offset)]))

;; ex:
(date*->moment/offset (current-date) -18000)
```

This (or Ryan's approach, which uses SRFI 19 instead of Gregor) will work
fine if you only need UTC offsets. If, however, you need to work with
proper time zones (like America/New_York) -- which you will if you need to
do any date arithmetic on localized dates -- then you'll want to stick with
Gregor.

About the Gregor documentation, it would be great if you could drop me a
note with suggestions for improving it.

- 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] find-seconds daylight saving

2016-11-08 Thread Jon Zeppieri
On Tue, Nov 8, 2016 at 6:26 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:

>
>
> On Tue, Nov 8, 2016 at 6:18 PM, George Neuner <gneun...@comcast.net>
> wrote:
>
>>
>> On 11/8/2016 2:29 PM, Robby Findler wrote:
>>
>>> find-seconds returns a number, not a date? Maybe seconds->date is the
>>> culprit here?
>>>
>>> Robby
>>>
>>
>> Spoke too soon.  1 combination gets it right:  (seconds->date
>> (find-seconds ... #F) #T).
>>
>> Note that (for me)  Nov 6 should be DST [until 2AM], but Nov 7 should be
>> EST.
>>
>>   --
>> (require racket/date)
>>
>> (seconds->date (find-seconds 0 0 0 6 11 2016 #f) #f)
>> (seconds->date (find-seconds 0 0 0 6 11 2016 #f) #t)
>> (seconds->date (find-seconds 0 0 0 6 11 2016 #t) #f)
>> (seconds->date (find-seconds 0 0 0 6 11 2016 #t) #t)
>> (displayln "")
>> (seconds->date (find-seconds 0 0 0 7 11 2016 #f) #f)
>> (seconds->date (find-seconds 0 0 0 7 11 2016 #f) #t)
>> (seconds->date (find-seconds 0 0 0 7 11 2016 #t) #f)
>> (seconds->date (find-seconds 0 0 0 7 11 2016 #t) #t)
>>
>> =>
>> date* 0 0 0 6 11 2016 0 310 #f 0 0 "UTC")
>> (date* 0 0 20 5 11 2016 6 309 #t -14400 0 "Eastern Daylight Time")
>> (date* 0 0 4 6 11 2016 0 310 #f 0 0 "UTC")
>> (date* 0 0 0 6 11 2016 0 310 #t -14400 0 "Eastern Daylight Time")
>>
>> (date* 0 0 0 7 11 2016 1 311 #f 0 0 "UTC")
>> (date* 0 0 19 6 11 2016 0 310 #f -18000 0 "Eastern Standard Time")
>> (date* 0 0 5 7 11 2016 1 311 #f 0 0 "UTC")
>> (date* 0 0 0 7 11 2016 1 311 #t -14400 0 "Eastern Daylight Time")
>>   --
>>
>>
>
> George, these are not correct results. The UTC offset is correct, but the
> time fields are not -- under the assumption that you're trying to
> round-trip them unchanged. (But maybe that's not a correct assumption.) At
> any rate, I think your original example demonstrates a problem with
> seconds->date on Windows.
>
>
>


Sorry, that was confusing. What I meant to say was: the results are correct
(given the treatment of the original date fields as UTC and the treatment
of the resulting seconds as local), but based on your original post, I
don't think they're the results you were after. But I'm not certain of that.

- 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] find-seconds daylight saving

2016-11-08 Thread Jon Zeppieri
On Tue, Nov 8, 2016 at 6:18 PM, George Neuner  wrote:

>
> On 11/8/2016 2:29 PM, Robby Findler wrote:
>
>> find-seconds returns a number, not a date? Maybe seconds->date is the
>> culprit here?
>>
>> Robby
>>
>
> Spoke too soon.  1 combination gets it right:  (seconds->date
> (find-seconds ... #F) #T).
>
> Note that (for me)  Nov 6 should be DST [until 2AM], but Nov 7 should be
> EST.
>
>   --
> (require racket/date)
>
> (seconds->date (find-seconds 0 0 0 6 11 2016 #f) #f)
> (seconds->date (find-seconds 0 0 0 6 11 2016 #f) #t)
> (seconds->date (find-seconds 0 0 0 6 11 2016 #t) #f)
> (seconds->date (find-seconds 0 0 0 6 11 2016 #t) #t)
> (displayln "")
> (seconds->date (find-seconds 0 0 0 7 11 2016 #f) #f)
> (seconds->date (find-seconds 0 0 0 7 11 2016 #f) #t)
> (seconds->date (find-seconds 0 0 0 7 11 2016 #t) #f)
> (seconds->date (find-seconds 0 0 0 7 11 2016 #t) #t)
>
> =>
> date* 0 0 0 6 11 2016 0 310 #f 0 0 "UTC")
> (date* 0 0 20 5 11 2016 6 309 #t -14400 0 "Eastern Daylight Time")
> (date* 0 0 4 6 11 2016 0 310 #f 0 0 "UTC")
> (date* 0 0 0 6 11 2016 0 310 #t -14400 0 "Eastern Daylight Time")
>
> (date* 0 0 0 7 11 2016 1 311 #f 0 0 "UTC")
> (date* 0 0 19 6 11 2016 0 310 #f -18000 0 "Eastern Standard Time")
> (date* 0 0 5 7 11 2016 1 311 #f 0 0 "UTC")
> (date* 0 0 0 7 11 2016 1 311 #t -14400 0 "Eastern Daylight Time")
>   --
>
>

George, these are not correct results. The UTC offset is correct, but the
time fields are not -- under the assumption that you're trying to
round-trip them unchanged. (But maybe that's not a correct assumption.) At
any rate, I think your original example demonstrates a problem with
seconds->date on Windows.

-- 
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] find-seconds daylight saving

2016-11-08 Thread Jon Zeppieri
I think Robby is right and the problem is here:
https://github.com/racket/racket/blob/4ce947da74d09abc9cda10a14e7407cda9386a44/racket/src/racket/src/fun.c#L9876

Well, that and the next line. There's only a `return 1;` for the case where
the given day-of-month is less than the DST change's day-of-month, but no
`return 0;` for the case where it's greater. All of the other comparisons
use the `dtxCOMP` macro, which handles both cases:

```
# define dtxCOMP(f) if (a->f < b->f) return 1; if (a->f > b->f) return 0;
```

Does that sound right? I don't have a Windows system at the moment, and I
can't reproduce on OS X.


- Jon




On Tue, Nov 8, 2016 at 2:29 PM, Robby Findler 
wrote:

> find-seconds returns a number, not a date? Maybe seconds->date is the
> culprit here?
>
> Robby
>
> On Tue, Nov 8, 2016 at 12:32 PM, George Neuner 
> wrote:
> >
> > Racket 6.6 on Windows 7.
> >
> > find-seconds is getting the time zone wrong when local-time? is #t.
> > Somehow it is in daylight saving all through November.
> >
> > When local-time? is #f (UTC) the time zone and hour offset are
> > correct. [At least for "fall back", didn't check "spring ahead"]
> >
> >
> >
> > (for* [(m '(11 12))
> >(d (in-range 1 31))
> >#:unless [and (= m 12)(> d 5)]
> >   ]
> >   (println (seconds->date (find-seconds 0 0 0 d m 2016 #t
> >
> > =>
> > (date* 0 0 0 1 11 2016 2 305 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 2 11 2016 3 306 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 3 11 2016 4 307 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 4 11 2016 5 308 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 5 11 2016 6 309 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 6 11 2016 0 310 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 7 11 2016 1 311 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 8 11 2016 2 312 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 9 11 2016 3 313 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 10 11 2016 4 314 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 11 11 2016 5 315 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 12 11 2016 6 316 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 13 11 2016 0 317 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 14 11 2016 1 318 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 15 11 2016 2 319 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 16 11 2016 3 320 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 17 11 2016 4 321 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 18 11 2016 5 322 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 19 11 2016 6 323 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 20 11 2016 0 324 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 21 11 2016 1 325 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 22 11 2016 2 326 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 23 11 2016 3 327 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 24 11 2016 4 328 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 25 11 2016 5 329 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 26 11 2016 6 330 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 27 11 2016 0 331 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 28 11 2016 1 332 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 29 11 2016 2 333 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 30 11 2016 3 334 #t -14400 0 "Eastern Daylight Time")
> > (date* 0 0 0 1 12 2016 4 335 #f -18000 0 "Eastern Standard Time")
> > (date* 0 0 0 2 12 2016 5 336 #f -18000 0 "Eastern Standard Time")
> > (date* 0 0 0 3 12 2016 6 337 #f -18000 0 "Eastern Standard Time")
> > (date* 0 0 0 4 12 2016 0 338 #f -18000 0 "Eastern Standard Time")
> > (date* 0 0 0 5 12 2016 1 339 #f -18000 0 "Eastern Standard Time")
> >
> >
> > George
> >
> > --
> > 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.
>
> --
> 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.
>

-- 
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] Recursive stepping down a list patially?

2016-10-31 Thread Jon Zeppieri
On Mon, Oct 31, 2016 at 11:28 PM,  wrote:

>
> Hi Jon,
>
> thanks for reply! :)
>
> My plan was, to return only one element from that list and
> possibly some extra informations and pass that to the processing
> function so it could right jump onto that train...
>
> Is that possible?
>
>
I think I understand your concern, and I think it's misplaced. Here's what
I think you're suggesting: you don't want to return the entire remainder of
the list, because (as you said) it's a really long list, and you're
concerned about passing around (and possibly duplicating) a ton of data.
But that's not the way it works. In terms of in-memory representation, all
that the `member` functions return is a pointer to a position (a particular
pair) in the original list.

You seem to be thinking of something like this: if you were using a vector,
you could return the element and the index where you found that element.
Then you could continue on from the next index. And you wouldn't want to do
this with a list, because if you start at the head of the original list,
you'd first have to follow it down to the nth element before continuing on,
and that would be inefficient. But what I'm saying is that if you simply
return the tail of the list using a `member` function, you don't incur that
extra iteration cost, and you don't duplicate any of the original list.

- 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] Recursive stepping down a list patially?

2016-10-31 Thread Jon Zeppieri
On Mon, Oct 31, 2016 at 10:53 PM,  wrote:

> Hi,
>
> I have a lng list of something. And I have a recursive serach
> function to crawl down the list and search for a previously determined
> item.
> When found, the search processes stops and returns that item of the
> list.
>
> In a second step, I want to process the list starting with that
> certain item til the end of the list.
>
> Is it possible to jump right into a list at a certain item of
> the list and to start processing there? Could the search function
> return a certain extra information so that another function could
> pick up that item directly and start recursing from there?
> """Distributed recursion""" somehow...?
>
>
The tail of a non-empty list is simply a list, so, if I understand you
correctly, what you want to do is very straightforward. The `member` (and
`memq` / `memv` / `memf` ) functions are meant for exactly this sort of
thing. In your first step, instead of returning just the member of the list
you're interested in, you can return the sublist that starts with that
item. For example, let's say you have a list of strings that looks like
this:

(define xs '("one" "two" "three" "four" "five"))

And you want to find "three." Then you can do:

(member "three" xs)

... which returns:

'("three" "four" "five")

The first element of the result is the element you wanted, and the
remainder of the list is everything after it.

You'll want `memf` if you need to search by some arbitrary function. See
the documentation for this group of functions.

- 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.


[racket-users] Convention for package build scripts (that don't really have to be part of the package)?

2016-10-28 Thread Jon Zeppieri
When I made recent changes to my tzdata package, I included a module that
automates the process of re-building the package. (It downloads the latest
version of the tz data and its associated code, builds the zoneinfo
database from it, and constructs an info.rkt file for it.) I have a similar
kind of script in the works for my next version of the CLDR packages.

Is there any kind of convention about where this kind of code should go?
For obvious reasons, I want it to be in the same repository as the package
itself, but it really doesn't need to be distributed as part of the
package. I could put it in its own -build directory from the repo
root, just like I might have -lib, -doc, and -test packages. (The -test
packages aren't terribly interesting from a distribution standpoint either.)

I'm just curious if anyone else has thought about this or has any good
ideas.

- 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] Structs vs Lists

2016-10-27 Thread Jon Zeppieri
On Thu, Oct 27, 2016 at 1:09 PM, Ken MacKenzie  wrote:

> Thank you that makes sense.  Vectors are fixed length so in theory could I
> also say a Vector is possibly more performant than an equivalent list?
>
> Ken
>

For accessing an arbitrary member, yes. A Racket vector is like, say, a C
array: it's a contiguous chunk of memory, and you can get at any member of
it in constant time.

For other purposes? Depends on the purpose. A struct is superior to a list
for struct-like operations. A list is superior to a struct for list-like
operations.

-- 
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] Structs vs Lists

2016-10-27 Thread Jon Zeppieri
On Thu, Oct 27, 2016 at 12:16 PM, Ken MacKenzie 
wrote:

> This is a question more about the footprint of each.  Deep down is a
> Struct really just syntactic sugar over a list.


Not in Racket (or in most Lisps these days).



> As in most things in Lisp from my understanding are all just lists, it is
> the basic building block of all data.  Is a struct also just a list and the
> element names enumerations of the fields by position.
>

In terms of its representation in memory, a Racket struct is more like a
vector than a list.


>
> Basically I am trying to figure out, without writing a benchmark test, if
> there is any processing overhead in using a struct instead of a list with
> enumerated field names.
>

It should generally be more efficient to access an arbitrary struct field
than an arbitrary list member.


>
> Ken
>
> --
> 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.
>

-- 
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] Unable to track down what is requiring inclusion of tzinfo module - Resolved

2016-10-22 Thread Jon Zeppieri
I changed the tzinfo and tzdata packages to remove the dynamic-require
behavior. If tzdata is installed, then tzinfo will use the data and will
define a runtime path list referring to the data files, so this should work
with `raco exe` now without needing to modify anything. Ian, if you have
the time, can you confirm that this works for you?

(Of course, if you're not on Windows, you won't need the tzdata package,
but the previous way that the code tried to use it would break with `raco
exe` regardless of what system you use.)

- Jon



On Fri, Oct 21, 2016 at 3:50 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:

> This connects to a similar issue I was having with my reorganization of
> the CLDR libraries (which I'm getting back into): https://groups.google.c
> om/d/msg/racket-dev/MrmxvvKidj8/ASEF22_lBQAJ.
>
> It looks like, in the present case, I should do something like this:
>
>
> - The tzdata package includes, in its info.rkt:
>
> (define tzdata-data-files )
>
> I suppose each of the paths should have the form (list 'lib
> "tzinfo/private/data/<...>"), based on the current directory structure of
> the tzdata package.
>
> - The tzinfo code then does something like:
>
> (define-runtime-path-list tzdata-paths
>   (match (find-relevant-directories '(tzdata-data-files))
> [(cons dir _)
>   ((get-info/full dir) 'tzdata-data-files)]
> [_ #f]))
>
> Does that sound right?
>
> - Jon
>
>
>
>
> On Fri, Oct 14, 2016 at 12:39 AM, Sam Tobin-Hochstadt <
> sa...@cs.indiana.edu> wrote:
>
>> That's likely the problem. Usually you need to use define-runtime-path or
>> a variant of that to cooperate with raco exe.
>>
>> Sam
>>
>

-- 
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] Unable to track down what is requiring inclusion of tzinfo module - Resolved

2016-10-21 Thread Jon Zeppieri
This connects to a similar issue I was having with my reorganization of the
CLDR libraries (which I'm getting back into): https://groups.google.
com/d/msg/racket-dev/MrmxvvKidj8/ASEF22_lBQAJ.

It looks like, in the present case, I should do something like this:


- The tzdata package includes, in its info.rkt:

(define tzdata-data-files )

I suppose each of the paths should have the form (list 'lib
"tzinfo/private/data/<...>"), based on the current directory structure of
the tzdata package.

- The tzinfo code then does something like:

(define-runtime-path-list tzdata-paths
  (match (find-relevant-directories '(tzdata-data-files))
[(cons dir _)
  ((get-info/full dir) 'tzdata-data-files)]
[_ #f]))

Does that sound right?

- Jon




On Fri, Oct 14, 2016 at 12:39 AM, Sam Tobin-Hochstadt 
wrote:

> That's likely the problem. Usually you need to use define-runtime-path or
> a variant of that to cooperate with raco exe.
>
> Sam
>

-- 
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: date->seconds complaining about a supposedly non-existent date

2016-10-21 Thread Jon Zeppieri
On Fri, Oct 21, 2016 at 12:17 AM, Jack Firth  wrote:

> There's also the Gregor package (https://docs.racket-lang.org/
> gregor/index.html?q=gregor), which gives a much more comprehensive
> interface to dates and times. In particular, Gregor allows you to specify
> an "offset resolver" for these sorts of time-holes.
>
>
I'd just add to this that if you're not using local times at all (which
seems to be the case here), you're better off using Gregor's `datetime`
type (instead of `moment`). That way you don't need to worry about time
zones and their idiosyncrasies.

-- 
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] Unable to track down what is requiring inclusion of tzinfo module - Resolved

2016-10-13 Thread Jon Zeppieri
I'm sure someone else knows better than I do, but I guess the problem is
that this technique (using `resolve-module-path` and `dynamic-require`)
won't work with `raco exe`. Is that right? Or is something else going on?

- Jon


On Thu, Oct 13, 2016 at 8:55 PM, Ian Thomas  wrote:

> On Thursday, October 13, 2016 at 6:18:56 PM UTC-4, Ian Thomas wrote:
> >
> > I installed "gregor" using the following raco command.
> >
> >   raco pkg install gregor
> >
> > My Racket installation looks in the following directories for
> Collections:
> >
> > racket@setup/dirs> (get-collects-search-dirs)
> > '(#
> >   #
> >   #)
> >
> > Contents of "Users/ian/Library/Racket/6.6/collects", which includes
> tzinfo and the rest of Gregor's dependencies.
> >
> > $ ls ~/Library/Racket/6.6/pkgs/
> > cldr-bcp47cldr-dates-modern   cldr-numbers-modern
>  gregor-doc  memoize tzinfo
> > cldr-core cldr-localenames-modern gregor
> gregor-lib  pkgs.rktd
> >
> > I built my executable using the following raco command.
> >
> >   raco exe -o date_analyzer driver.rkt
> >
> > The executable works without issue if I don't require
> "../lib/date_analysis.rkt", which requires "gregor", but then, of course,
> I'm not able to do any date analysis.
> >
> > This one's a real mystery. Any further suggestions welcome.
>
> The issues appears to be with the tzinfo package itself that attempts to
> require submodule zoneinfo-data, but there is no zoneinfo-data submodule in
> tzinfo, nor is there currently a tzinfo/zoneinfo-data package period.
>
> $ grep zoneinfo-data -r *
> Binary file tzinfo/tzinfo/compiled/main_rkt.zo matches
> tzinfo/tzinfo/main.rkt:;; Load the zoneinfo-data package, if it's installed
> tzinfo/tzinfo/main.rkt:  (and (file-exists? (resolve-module-path
> 'tzinfo/zoneinfo-data #f))
> tzinfo/tzinfo/main.rkt:   (dynamic-require 'tzinfo/zoneinfo-data
> 'ZONEINFO-DATA)))
>
> $ find tzinfo/ -iname 'zoneinfo-data*'
> $
>
> Maybe tzinfo worked with a previous version of OS X: I'm running Sierra.
>
> $ uname -rsv
> Darwin 16.0.0 Darwin Kernel Version 16.0.0: Mon Aug 29 17:56:20 PDT 2016;
> root:xnu-3789.1.32~3/RELEASE_X86_64
>
> I resolved the issue by commenting out the following lines in
> tzinfo/tzinfo/main.rkt:
>
> ;;(define ZONEINFO-DATA
> ;;  (and (file-exists? (resolve-module-path 'tzinfo/zoneinfo-data #f))
> ;;   (dynamic-require 'tzinfo/zoneinfo-data 'ZONEINFO-DATA)))
>
> re-running raco setup, and finally recompiled my executable.
>
> --
> 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.
>

-- 
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] Constructing unicode surrogates

2016-10-08 Thread Jon Zeppieri
On Sat, Oct 8, 2016 at 1:06 PM, Jens Axel Søgaard 
wrote:

> Hi All,
>
> The following interaction shows how the reader can be used to construct a
> surrogate character:
>
> > (string-ref "\ud800\udc00" 0)
> #\
>
> Given the two hexadecimal numbers d800 and dc00 how do I
> construct the surrogate character directly?
>
> /Jens Axel
>
>
I think you have to do the arithmetic yourself. Something like:

(define (utf-16-surrogate-pair->char hi lo)
  (integer->char
   (+ #x1
  (arithmetic-shift (bitwise-and hi #x03ff) 10)
  (bitwise-and lo #x03ff

-- 
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] Using schemas with the 'db' module

2016-10-06 Thread Jon Zeppieri
Ah, my mistake. Thanks!

> On Oct 6, 2016, at 6:42 PM, Ryan Culpepper <ry...@ccs.neu.edu> wrote:
> 
> In PostgreSQL, clusters contain databases contain schemas.
> 
> I think the answer is to use "SET SCHEMA" or the more general "SET 
> search_path". See
> 
>  https://www.postgresql.org/docs/current/static/ddl-schemas.html
>  https://www.postgresql.org/docs/current/static/sql-set.html
> 
> Ryan
> 
>> On 10/06/2016 06:21 PM, Jon Zeppieri wrote:
>> Isn't the #:database parameter in postgresql-connect what you're looking
>> for?
>> 
>> On Oct 6, 2016, at 6:12 PM, David Storrs <david.sto...@gmail.com
>> <mailto:david.sto...@gmail.com>> wrote:
>> 
>>> Is it possible to connect to a specific schema in a Postgres database,
>>> or to set the current schema of an existing connection?
>>> 
>>> The 'postgresql-connect' function has no parameter for schema...in
>>> fact, the only mention of schemas in the docs for db is in the
>>> Database Catalog section
>>> (https://docs.racket-lang.org/db/query-api.html#%28part._.Database_.Catalog_.Information%29)
>>> 
>>> --
>>> 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
>>> <mailto:racket-users+unsubscr...@googlegroups.com>.
>>> For more options, visit https://groups.google.com/d/optout.
>> 
>> --
>> 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
>> <mailto:racket-users+unsubscr...@googlegroups.com>.
>> For more options, visit https://groups.google.com/d/optout.
> 

-- 
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] Using schemas with the 'db' module

2016-10-06 Thread Jon Zeppieri
Isn't the #:database parameter in postgresql-connect what you're looking for?

> On Oct 6, 2016, at 6:12 PM, David Storrs  wrote:
> 
> Is it possible to connect to a specific schema in a Postgres database, or to 
> set the current schema of an existing connection?  
> 
> The 'postgresql-connect' function has no parameter for schema...in fact, the 
> only mention of schemas in the docs for db is in the Database Catalog section 
> (https://docs.racket-lang.org/db/query-api.html#%28part._.Database_.Catalog_.Information%29)
> 
> -- 
> 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.

-- 
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] sequence of moments?

2016-09-22 Thread Jon Zeppieri


> On Sep 22, 2016, at 3:57 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
> 
> 
> 
>>> On Sep 22, 2016, at 3:43 PM, Geoffrey Knauth <ge...@knauth.org> wrote:
>>> 
>>> On Thursday, September 22, 2016 at 3:17:50 PM UTC-4, Jon Zeppieri wrote:
>>> Oh, sorry: I thought you wanted a sequence of moments from start and end 
>>> *seconds*. If you're starting with moments, you could just repeatedly add a 
>>> second (if that's the increment you want).
>> 
>> The increment is a day (specifically 2016-01-01 through 2016-08-31, 00Z each 
>> day.  I was looking for a sequence so I could convert it a list and then map 
>> a function that takes a moment over the list.
> 
> I'm on my phone right now, so I can't actually test any code, but it should 
> be pretty straightforward to create this:
> 
> (make-do-sequence
>  values
>  (lambda (x) (+days x 1))
>  start-moment
>  (lambda (x) (moment  #f
>  #f)
> 
> You may want to use an explicit offset resolver with +days, in case you land 
> on a moment that doesn't exist in your chosen time zone.
> 

Oh, but if you're just using UTC moments, you might consider using datetime 
instead of moment. That way you don't need to worry about discontinuous 
timelines at all.


>> 
>> -- 
>> 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.

-- 
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] sequence of moments?

2016-09-22 Thread Jon Zeppieri


> On Sep 22, 2016, at 3:43 PM, Geoffrey Knauth <ge...@knauth.org> wrote:
> 
>> On Thursday, September 22, 2016 at 3:17:50 PM UTC-4, Jon Zeppieri wrote:
>> Oh, sorry: I thought you wanted a sequence of moments from start and end 
>> *seconds*. If you're starting with moments, you could just repeatedly add a 
>> second (if that's the increment you want).
> 
> The increment is a day (specifically 2016-01-01 through 2016-08-31, 00Z each 
> day.  I was looking for a sequence so I could convert it a list and then map 
> a function that takes a moment over the list.

I'm on my phone right now, so I can't actually test any code, but it should be 
pretty straightforward to create this:

(make-do-sequence
  values
  (lambda (x) (+days x 1))
  start-moment
  (lambda (x) (moment 
> -- 
> 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.

-- 
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] sequence of moments?

2016-09-22 Thread Jon Zeppieri


> On Sep 22, 2016, at 3:12 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
> 
> 
> 
>> On Sep 22, 2016, at 2:04 PM, Geoffrey Knauth <ge...@knauth.org> wrote:
>> 
>> Is it possible to build a sequence of moments?  (require gregor)
>> 
>> I had a sequence of seconds (since the epoch), as in:
>> 
>> (in-range start-seconds end-seconds seconds-in-a-day)
>> 
>> If I use moments, I'm wondering what goes in place of _HMM_:
>> 
>> (in-range start-moment end-moment _HMM_)
> 
> This should be more convenient than it is. There's a posix->datetime, and 
> then you'd have to construct a new moment from the resulting datetime's data, 
> plus a TZ. 
> 
> Internally, there's a function that makes this much easier, but it's not 
> provided. 
> 
> My apologies; I promise that the replacement library will make this easier.
> 
> - Jon
> 
> 

Oh, sorry: I thought you wanted a sequence of moments from start and end 
*seconds*. If you're starting with moments, you could just repeatedly add a 
second (if that's the increment you want).



>> 
>> -- 
>> You received this message because you we 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.

-- 
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] sequence of moments?

2016-09-22 Thread Jon Zeppieri


> On Sep 22, 2016, at 2:04 PM, Geoffrey Knauth  wrote:
> 
> Is it possible to build a sequence of moments?  (require gregor)
> 
> I had a sequence of seconds (since the epoch), as in:
> 
>  (in-range start-seconds end-seconds seconds-in-a-day)
> 
> If I use moments, I'm wondering what goes in place of _HMM_:
> 
>  (in-range start-moment end-moment _HMM_)

This should be more convenient than it is. There's a posix->datetime, and then 
you'd have to construct a new moment from the resulting datetime's data, plus a 
TZ. 

Internally, there's a function that makes this much easier, but it's not 
provided. 

My apologies; I promise that the replacement library will make this easier.

- Jon


> 
> -- 
> You received this message because you we 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.

-- 
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] Persisting large values for debugging long-running programs

2016-09-14 Thread Jon Zeppieri


> On Sep 14, 2016, at 4:24 PM, 'John Clements' via Racket Users 
>  wrote:
> 
> Just in case this information is useful:
> 
> The “classical” hack here—Eli showed me this, I believe—is to write the data 
> out in the form of a file that “provide”s the specified datum, then compile 
> it to a “.zo” file. It seems plausible to me that loading a compiled .zo file 
> might be the fastest way of reading in data. Then again, if you use a 
> database as others have suggested you might be able to bypass racket’s 
> loading altogether.
> 
> John

Isn't fasl the format used in .zo files? 

-- 
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] Persisting large values for debugging long-running programs

2016-09-14 Thread Jon Zeppieri
'Course you already mentioned a custom encoding, so, yeah, fasl: 
https://docs.racket-lang.org/reference/fasl.html

> On Sep 14, 2016, at 3:47 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
> 
> I think reading and writing fasl should be faster, but don't expect the 
> format to be compatible across Racket versions.
> 
> Or, if you know some super-efficient encoding for your data, wrap it in a new 
> struct type and implement your own serialization.
> 
>> On Sep 14, 2016, at 3:38 PM, Jonathan Schuster <schus...@ccs.neu.edu> wrote:
>> 
>> I have some large (several GB worth) sets of values I'd like to persist 
>> across debugging runs of a program, rather than recomputing them each time. 
>> I'm currently doing this with the built-in "read" and "write", but is there 
>> a more efficient method, especially for reading the data back in?
>> 
>> I could of course come up with some kind of custom encoding, but that's 
>> likely not worth the effort in my case, so I'm wondering if there's any 
>> general purpose method already available in Racket (or in a package).
>> 
>> Thanks,
>> 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.

-- 
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] Persisting large values for debugging long-running programs

2016-09-14 Thread Jon Zeppieri
I think reading and writing fasl should be faster, but don't expect the format 
to be compatible across Racket versions.

Or, if you know some super-efficient encoding for your data, wrap it in a new 
struct type and implement your own serialization.

> On Sep 14, 2016, at 3:38 PM, Jonathan Schuster  wrote:
> 
> I have some large (several GB worth) sets of values I'd like to persist 
> across debugging runs of a program, rather than recomputing them each time. 
> I'm currently doing this with the built-in "read" and "write", but is there a 
> more efficient method, especially for reading the data back in?
> 
> I could of course come up with some kind of custom encoding, but that's 
> likely not worth the effort in my case, so I'm wondering if there's any 
> general purpose method already available in Racket (or in a package).
> 
> Thanks,
> 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.

-- 
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: lambda and the equivalent define / "defun"

2016-09-07 Thread Jon Zeppieri
On Wed, Sep 7, 2016 at 12:18 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:

>
> Note that this function still generates a list as output. I suppose it
> could instead generate as many values as there are initial elements of xs,
>


Uh, and you can disregard this statement altogether, since it's crazy
[sorry]. `foldl*`, like `foldl`, does not need to generate a list as output.

-- 
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: lambda and the equivalent define / "defun"

2016-09-07 Thread Jon Zeppieri
On Wed, Sep 7, 2016 at 12:18 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:

>
>
> ```
> #lang racket/base
>
> (require racket/match)
>
> (define (foldl* proc init . xs)
>   (match xs
> ['() init]
> [(cons x xs) (apply foldl* proc (proc x init) xs)]))
> ```
>
>
I should provide an example. So, if you were using the normal `foldl`,
you'd have:

```
> (foldl cons '() '(1 2 3 4))
'(4 3 2 1)
```

Instead, here's you'd do:

```
> (foldl* cons '() 1 2 3 4)
'(4 3 2 1)
 ```

-- 
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: lambda and the equivalent define / "defun"

2016-09-07 Thread Jon Zeppieri
On Wed, Sep 7, 2016 at 11:54 AM, Sanjeev Sharma  wrote:

> Just illustrates the changing structure (increased nesting depth) on each
> recursive call
>
> The initial call to t2 changes the structure of the 
> argument/parameter - it puts in a list where there was no list.
>
> Each recursive call from inside t2 again changes the structure, adding an
> enclosing '() for the  parameter
>
> For the usual (no ) function call It's not an issue for the standard
> car/cdr idiom of walking down recursive structures.
>
>
Okay, I think I follow you.

My first piece of advice (which I think I already mentioned) is to use a
fixed-arity helper function. I understand that you want to do this without
a helper function, but, really, using a helper function is the idiomatic
approach. That said, I'll provide an example of a recursive variable-arity
function that uses `apply` instead. The purpose of `apply` is to use the
individual members of a list as separate arguments to a function call.
Here's a vararg version of `foldl`, limited to a single input "list":

```
#lang racket/base

(require racket/match)

(define (foldl* proc init . xs)
  (match xs
['() init]
[(cons x xs) (apply foldl* proc (proc x init) xs)]))
```

In the recursive case, `apply` is used to provide the elements of xs as
separate arguments to `foldl*`. Note that this function still generates a
list as output. I suppose it could instead generate as many values as there
are initial elements of xs, but that would be an awful pain to use.

- 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: lambda and the equivalent define / "defun"

2016-09-07 Thread Jon Zeppieri
On Wed, Sep 7, 2016 at 8:33 AM, Sanjeev Sharma  wrote:

> Thanks for joining in.
>
> The amended question had nothing to do with the earlier example
>

Okay.


>
> I'm  wondering if there's a quick, standard (and easily understood) idiom
> (without an internal helper function) to recur on the variable argument
> list y
>

I'm still not sure what you mean, and I don't understand what your `t2`
example is supposed to do.

-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: lambda and the equivalent define / "defun"

2016-09-06 Thread Jon Zeppieri
On Tue, Sep 6, 2016 at 8:50 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:
>
>
>
> The `(lambda s ...)` is variable-arity, but when you call `ss` internally
> [...]
>

Sorry, I realized after that your `ss` function essentially *is* a wrapper
around your `subsets` function -- which is exactly what I was suggesting.
However, there's no reason for it to duplicate so much of the work of
`subsets`. Since `subsets` works on any list, your definition of `ss` can
simply be:

(define (ss . xs) (subsets xs))

The only purpose of `ss` is to package up its arguments as a list and pass
that list to `subsets`.

- 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: lambda and the equivalent define / "defun"

2016-09-06 Thread Jon Zeppieri
On Tue, Sep 6, 2016 at 7:30 PM, Sanjeev Sharma  wrote:

> Thanks, that's helpful
>
> I am having trouble coming up with a quick and easy shorthand to recur on
> the rest parameter - is there a standard way to cdr down this list without
> an intermediary helper function that takes out the raise-nesting-depth
> effect?
>
> Recursion on the base define (the one with the rest parameter) always adds
> another layer of nesting for the rest parameter - the first time recurring
> one must cdr, all the other times one must fiddle with car & cdr and what
> I'm doing has been prone working for the first few iterations but
> eventually arity-mismatches.
>
>
>From your description, the arity mismatches are probably caused by the fact
that you're defining `subsets` as a variable arity function, but internally
the recursive uses assume that it takes a single list. Your code in the
original post was:

(define ss
  (lambda s
(if (null? s)
  (list nil)
  (let ((rest (subsets (cdr s
(append
 rest
 (map
  (lambda (x)
(append (list (car s))
x))
  rest))


The `(lambda s ...)` is variable-arity, but when you call `ss` internally,
you're always passing a single list as the argument. If you want a
variable-arity version, the simplest way is to define it as a simple
wrapper around a recursive fixed-arity version. Alternatively, you could
use `apply` in your recursive calls, but I'd call that bad style.

-- 
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] equivalence relation for hash keys

2016-08-04 Thread Jon Zeppieri
On Thu, Aug 4, 2016 at 12:34 PM, Jos Koot  wrote:

> Hi
>
> As far as I can see a hash has three options only for the equivalence
> relation comparing keys: eq?, eqv? and equal?.
> Would it be possible to extend Racket such as to allow the preparation of
> hashes with a user specified equivalence relation?
>
> May be I can prepare it myself, but I have no idea where to start.
> Pointers welcome, of course.
>
> For example, I am interested in a hash with the following equivalence
> relation for its keys:
>
> (lambda (x y) (equal? (sort x <) (sort y <)))
> x : exact-nonnegative-integer?
> y : exact-nonnegative-integer?
>
> Thanks, Jos
>


Or you could wrap your data (lists, I take it) in structs and define
methods for gen:equal+hash on your struct type.

-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] `eqv?` vs `eq?` for interned numbers & characters

2016-07-24 Thread Jon Zeppieri
On Mon, Jul 25, 2016 at 12:35 AM, Matthew Butterick  wrote:

> The docs say `eqv?` differs from `eq?` only for nmbers and characters. But
> is this still true since numbers and characters became interned data types
> in 2011? [1]
>

That mail thread is specifically about *literal* data being interned.



>
> If it were true I would've expected the docs to say so; OTOH the docs do
> not provide an example of, say, a pair of numbers where today's `eqv?` and
> `eq?` in fact give different results.
>


Non-interned bignums and non-interned characters with codepoints > 255 will
still behave differently under `eq?` and `eqv?`.

> (eq? (expt 9 999) (expt 9 999))
#f
> (eqv? (expt 9 999) (expt 9 999))
#t

> (eq? (integer->char 1500) (integer->char 1500))
#f
> (eqv? (integer->char 1500) (integer->char 1500))
#t



>
>
> [1] http://www.mail-archive.com/dev@racket-lang.org/msg04893.html
>
>
- 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] Is my model of (values) accurate?

2016-07-22 Thread Jon Zeppieri
On Fri, Jul 22, 2016 at 7:58 PM, David Storrs 
wrote:

> Thanks Jon, I appreciate the clear explanation.
>
> I'm using call-with-values in database code in order to turn a list into
> an acceptable set of bind parameters.  Here's an example:
>
> (query-exec conn "insert into foo (bar, baz) values ($1, $2)" (some-func))
>
> some-func returns a list, '("bob", "george").  query-exec throws an
> exception because it wants to see two elements for the bind parameters, not
> a list.  The solution I found was this:
>
> (call-with-values
> (lambda () (apply values the-list))
> (curry query-exec conn stmt))
>

Okay, so `some-func` produces a list, and you want that lists elements to
be provided as the last N arguments to query-exec. This is really what
`apply` is good for:

(apply query-exec conn "insert ..." (some-func))

should work for your case.

-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] Is my model of (values) accurate?

2016-07-22 Thread Jon Zeppieri
On Fri, Jul 22, 2016 at 6:30 PM, David Storrs 
wrote:

>
> The best mental model I've been able to come up with is that (values)
> returns its results vertically but most functions expect to get them
> horizontally and will die if there are parallel lines of uncollected
> values. Under this model (call-with-values) collects values from the Y
> axis and pivots them back onto the X axis for consumption by regular
> functions. This feels like a fragile analogy though.  Would someone
> please fill me in on how it actually works?
>
>

When you do:

   (values ...)

in a DrRacket window, it does list the values vertically, but that's
probably not a very useful way to think about what `values` is.  You can
think of `values` as a constructor of a second-class tuple. The fact that
the resultant tuple is "second-class" is very important here. You can't
give a name to this tuple. For example,

   (define foo (values 1 2 3))

is illegal.  You can't pass it as an argument to a procedure:

   (list (values 1 2 3))

is likewise illegal. There is, in fact, very little you can do with this
tuple other than let `call-with-values` unpack it.

`call-with-values` is special (like call-with-continuation is special). Its
first argument, a zero-arity procedure, produces a values which are then
passed *as separate arguments* -- not as a second-class tuple -- to its
second argument. That's what `call-with-values` does: it translates this
second-class tuple into separate procedure arguments.

`call-with-values` is rarely used directly. It's far more common to use
`define-values` or `let-values` (or one of its variants). For example,
although you can't do:

   (define foo (values 1 2 3))

You can do:

   (define-values (a b c) (values 1 2 3))

There is one special case to keep in mind: a unary use of `values`, e.g.:

   (values 1)

is exactly equivalent to its argument. That is, (values 1) *is exactly* 1.
That's not true for any other arity of `values`. (This is also how
*first*-class tuples in ML behave.)

For my own part, I'm not a big fan of `values` and `call-with-values`.
Their use is for returning multiple values from a procedure -- which you
can also do by returning a first-class, composite piece of data, like a
vector or a list. The one advantage of second-class tuples is that, because
there's so little you can do
with them, they're easier to give optimized representations.

- 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.


[racket-users] Re: How to differentiate between files and directories?

2016-07-21 Thread Jon Zeppieri
On Thu, Jul 21, 2016 at 3:59 PM, David Storrs 
wrote:

> So there's no way to query the interface of a struct?
>
>
>
Not in general, no. -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] How to differentiate between files and directories?

2016-07-21 Thread Jon Zeppieri
On Thu, Jul 21, 2016 at 2:44 PM, David Storrs 
wrote:
>
>
>
> In a related question, is there a way to introspect a struct to find
> out what its fields are?
>
>
If you mean the field values: yes, but only if the struct is transparent or
prefab or if you have the proper inspector, which you probably do not. You
can generally try struct->vector and see if you get anything useful.

If you mean the field names: I don't think so; I don't think they exist at
runtime.

- 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] How to differentiate between files and directories?

2016-07-21 Thread Jon Zeppieri
On Thu, Jul 21, 2016 at 2:44 PM, David Storrs 
wrote:

>
>
> I saw 'file-exists?' but I don't want to check the disk twice, I just
> want to know what type it is.  That information should have been
> available when the path was constructed.
>
>
Constructing a path doesn't require checking the filesystem, because a path
might not actually refer to anything extant. E.g.,

> (string->path "/foo/bar")
#

(There is nothing on my filesystem at /foo/bar.)

- 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] provide/contract with an id that doubles as a match expander

2016-06-09 Thread Jon Zeppieri
On Thu, Jun 9, 2016 at 2:24 PM, Alex Knauth  wrote:

>
>
> There's `define-module-boundary-contract`, which does something similar to
> `define/contract` except that it uses the module as a boundary instead of
> creating it's own:
>
> http://docs.racket-lang.org/reference/attaching-contracts-to-values.html?q=contract%20module%20boundary#%28form._%28%28lib._racket%2Fcontract%2Fprivate%2Fprovide..rkt%29._define-module-boundary-contract%29%29
>
>
>
Thanks Alex, that's helpful.

Now there's an additional wrinkle.

Let's say that `date` is provided by a private module and then re-provided
from a public one. We can either:

- use `date` without a contract internally and add the contract at the
public module boundary, or
- add the contract at the private module boundary (so that other modules in
the same package are required to obey the contract), in which case we'd
like to change the positive blame assignment when we re-export the
identifier from the public module.

The first option seems straightforward, given your previous reply. The
second seems straightforward only if we're willing to add a contract to the
already-contracted function. `recontract-out` is supposed to help with this
case, but it only works if the identifier was originally provided with
`contract-out`, and we can't use `contract-out`, since it won't allow the
identifier to be used as a match expander. There doesn't seem to be a way
to grab the un-contracted value from the impersonator created by either
`define/contract` or `define-module-boundary-contract`.

Ideally, I'd be able to specify a custom constructor (and match expander)
with `struct`, and everything would be taken care of by `(provide
(struct-out ...))` or `(provide/contract (struct ...))`.

- 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.


[racket-users] provide/contract with an id that doubles as a match expander

2016-06-09 Thread Jon Zeppieri
I think I've asked a question like this in the past, but I still haven't
found a good solution. I'm going to give a concrete example:

Let's say I have a `date` struct like this:

(struct date (y m d))


And I'm perfectly happy with the default match expander:

(match d
  [(date y m d) ...])


But I want a custom constructor:

(define (date* y [m 1] [d 1])
  (date y m d))


And, of course, I want to provide the custom constructor as `date`, not
`date*`:

(define make-date
  (procedure-rename
   (λ (y [m 1] [d 1])
 (date y m d))
   'date))

(define-match-expander $date
  (syntax-rules ()
[(_ y m d) (date y m d)])
  (λ (stx)
(syntax-case stx ()
  [(_ xs ...) #'(make-date xs ...)]
  [_ #'make-date])))

(provide (rename-out [$date date]))


But I also want to provide the constructor with a contract:

(provide/contract
  [rename
$date date
 (->i ([year exact-integer?])
   ([month (integer-in 1 12)]
[day (year month) (day-of-month/c year month)])
[d date?])])


Unfortunately, although this provides `date` as a constructor function, it
does not allow it to be used as a match expander.

What's the best way of getting both?

I think it might work if I defined `make-date` above with `define/contract`
(thus narrowing the contract boundary) and then doing the normal `(provide
(rename-out ...))`, as in the second-to-last example, above.

But is there a painless way to accomplish this without narrowing the
contract boundary?

-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] Case vs. Match

2016-06-03 Thread Jon Zeppieri
There's rarely a good reason. If you were dispatching over a very large set of 
constants -- fixnums or characters, in particular -- I'd expect better 
performance from case. That's about it.

> On Jun 3, 2016, at 10:10 AM, Gerald Pipes  
> wrote:
> 
> I have been recently using match a lot and I was wondering what was the main 
> benefit of using case instead of match?  It seems as though match has the 
> distribution on a single val-exp except match allows for the pattern matching 
> and case just uses equal?.  
> 
> -- 
> 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.

-- 
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] File Ports / Writing to a file

2016-04-20 Thread Jon Zeppieri
On Wed, Apr 20, 2016 at 5:03 PM, George Mitwasi <mitwasi.geo...@gmail.com>
wrote:

> On Wednesday, April 20, 2016 at 3:09:53 PM UTC-4, Jon Zeppieri wrote:
> > Maybe you're using one of the teaching languages instead of Racket
> proper? In the "Language" menu, if you select "Choose Language..." you'll
> see a dialog. It should tell you what language you're using.
> >
>
> Interesting. The default language is set to "The Racket Language" which
> surprisingly doesn't work. I tested my code with the other languages and
> R5RS was the winner. Thanks you sir!
>
>

That is odd. The code should certainly work in the Racket language. (The
documentation you cited is for Racket.) Maybe you don't have a `#lang` line
in your definitions window? If you're writing in Racket, the first line of
your program should be:

#lang racket

or (if you want to start with a smaller language):

#lang racket/base

If you omit the #lang line, it won't work. However, DrRacket will actually
tell you that, so you're probably experiencing some different problem.
Unfortunately, I don't know what it is. I *do* know that the sample code
you posted should work in either racket or racket/base.

-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] File Ports / Writing to a file

2016-04-20 Thread Jon Zeppieri
Maybe you're using one of the teaching languages instead of Racket proper?
In the "Language" menu, if you select "Choose Language..." you'll see a
dialog. It should tell you what language you're using.

-Jon


On Wed, Apr 20, 2016 at 3:05 PM, George Mitwasi 
wrote:

> There's a good chance this is a quick fix and that I've overlooked
> something.
>
> My goal is to simply write output to a text file directly from DrRacket.
> I've read through the documentation (
> https://docs.racket-lang.org/reference/file-ports.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._open-input-file%29%29)
> and am receiving errors with basic expressions like (define out
> (open-output-file some-file)). Racket doesn't recognize the expression.
>
> Am I missing a library (doesn't seem to be the case)? Are there some
> settings that I need change?
>
> Appreciate the help!
>
> - George
>
> --
> 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.
>

-- 
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] Case and eof

2016-04-04 Thread Jon Zeppieri
On Mon, Apr 4, 2016 at 3:40 PM, Jay McCarthy  wrote:

> case is just for integers and symbols.
>


I'm not sure if you meant this as a claim about how you think `case` should
be used, but it certainly does work for more than just integers and
symbols. It will work for any data with a literal reader syntax. -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] Include link in email: what headers to use?

2016-03-27 Thread Jon Zeppieri
On Sun, Mar 27, 2016 at 9:29 AM, Marc Kaufmann 
wrote:

> Ah, of course "extra-header ... " means there can be several of them -
> which I know, but forgot in this context. On the other hand, I also didn't
> realize that "Conten-Type: text/html; charset=iso-8859-1" was a single
> header either, so I would still have gotten it wrong.
>
> Works like a charm now, thank.
>
>
Also: unless you're explicitly encoding the message body as latin-1 (a.k.a.
iso-8859-1), it's probably better to use "charset=utf-8" in the
Content-Type header, since that's Racket's default string encoding. It
won't matter unless you use non-ASCII characters, but if you do, it will.

-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] Include link in email: what headers to use?

2016-03-26 Thread Jon Zeppieri
The `extra-header` parameter is a rest parameter, so you're supposed to
pass one string per header, not a single string containing all of them.
And, if you were going to send them all in a single string, you'd need to
separate them with an \r\n sequence, not with semicolons. So pass two
separate strings as the last two arguments:

"Return-Path: "
"Content-Type: text/html; charset=iso-8859-1"

-Jon

On Sun, Mar 27, 2016 at 1:18 AM, Marc Kaufmann 
wrote:

> Hi all,
>
> I am sending out emails with sendmail, and found a PHP thread [1] on the
> headers one should include in order to be able to use html in the emails -
> I want this only to make the links look nice, e.g.  href="i-am-long-and-ugly">Pretty.
>
> Unfortunately, adding "Return-Path: ;
> Content-type: text/html; charset=iso-8859-1;" as the extra-header string to
> sendmail has absolutely no effect and the html gets simply printed as text.
>
> I don't know whether this is due to Racket, sendmail, or the sendmail
> configuration on my system, so let me know if I should look elsewhere for
> solutions.
>
> Cheers,
> Marc
>
> [1]:
> http://stackoverflow.com/questions/15711700/php-mail-how-to-put-an-html-link-in-an-email
>
> --
> 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.
>

-- 
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] custom input ports

2016-03-14 Thread Jon Zeppieri
Almost every time I've created a custom input port, I've run up against the
rule: "The read-in procedure must not block indefinitely." And each time,
I've either:

- ignored it (with the suspicion that I've just written code that can block
the whole process, though I've never actually verified this);
- written a state machine that buffers data from the underlying port until
it has enough to work with; or
- created a new thread that reads from the underlying port and pipes data
back.

(By the way, `filter-read-input-port` doesn't help here, since the filter
is called in the context of the above-mentioned `read-in` procedure, so,
even though the docs don't mention it, presumably it shouldn't do blocking
I/O either.)

The last of these is the least painful (if you count the psychological pain
of option 1), but it raises another problem. If the data turns out to be
malformed, I want to raise an exception. (Or, at least, I think I do.) But
I want to raise it in the reader's thread, and I don't think there's a way
to do this, short of an explicit pre-arrangement.

Has anyone else dealt with this problem (and come up with a nice solution)?
I haven't yet tried using generators. They might make it a bit easier to do
a variation on option 2, at the cost of a bunch of stack-copying.

- 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.


[racket-users] ports, custodians, and places

2016-03-12 Thread Jon Zeppieri
I have TCP ports that I send from one place to another. I'd like the
receiving place to be responsible for closing them. In particular, I'd like
to make that the responsibility of a custodian in the receiving place.

If I close the ports in the receiving place, however, that doesn't actually
close the underlying socket, because the sending place still has an open
file descriptor for it. And it seems that if I close the ports immediately
after sending them via `place-channel-put`, that's too soon.

I could have the receiving place notify the sending one of receipt, at
which point the sender could close the ports -- I just tried this out, and
it works -- but that involves some undesirable bookkeeping overhead.
(Because I'm doing this in a loop, when I receive a message saying, "You
can close the ports now!" I need to keep track of exactly which set of
ports it's safe to close.)

Is there a better way to handle this? Maybe the implementation of
place-channel-put could dup the file descriptor and then close the
duplicate after sending it?

-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] Help writing a simple lexer/tokenizer

2016-02-22 Thread Jon Zeppieri
On Mon, Feb 22, 2016 at 7:26 PM, Neil Van Dyke  wrote:

> For someone who really wants to learn this well, rather than just make a
> lexer and move on...
>
> I started learning the pertinent theory (such as automata NFA/DFA, and
> classes of formal languages) from the original red dragon book:
> https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools
>
>
Also consider reading the paper "Regular-expression derivatives reexamined"
[https://www.mpi-sws.org/~turon/re-deriv.pdf]. It's what the
parser-tools/lex library is based on, and it takes an elegant, functional
approach to regular expression (and regular vector) matching.

-- 
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 writing a simple lexer/tokenizer

2016-02-22 Thread Jon Zeppieri
Have you looked at the parser-tools/lex library? 
https://docs.racket-lang.org/parser-tools/Lexers.html

> On Feb 22, 2016, at 4:46 PM, Federico Ramírez  wrote:
> 
> Hello everyone! I'm new to Scheme, and I need some help wrapping my head 
> around it.
> 
> I want to write a simple tokenizer, which is just a function that takes a 
> string as input and outputs a list of "tokens", which to keep thing simple is 
> a tuple of NAME and VALUE.
> 
> So, for example:
> 
> (tokenize "foo = 1") => '((IDENTIFIER . "foo") (EQUALS . "=") (NUMBER . 1))
> 
> I didn't want to use global variables to keep things functional, so my 
> solution doesn't use any, but I wouldn't mind much using them. This is some 
> code for my current implementation, I omit some code for brevity as it's 
> quite repetitive for now:
> 
>(define (match-identifier input)
>  (regexp-match #rx"^[a-zA-Z_]+"))
> 
>(define (consume-identifier input)
>  (let ([match (first (match-identifier input))])
>(cons `(IDENTIFIER . ,match) (tokenize (substring input (string-
> length match))
> 
>;; some more matchers and consumers, all pretty similar
>;; ...
> 
>(define (tokenize input)
>  (cond
>((match-identifier input) (consume-identifier input))
>((match-equals input) (consume-equals input))
>((match-number input) (consume-number input))
>(else '(
> 
> What bothers me is that it's calling the matchers twice for each token, which 
> isn't very good for performance and it's not pretty :p 
> 
> I want to get rid of that double-check. I figured I could use some globals in 
> order to do it but I'd rather not. 
> 
> Does anyone have a suggestion/fix on my implementation?
> 
> Thank you for your time :)
> 
> -- 
> 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.

-- 
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] second->date

2016-02-19 Thread Jon Zeppieri
On Fri, Feb 19, 2016 at 6:34 PM, Jos Koot <jos.k...@gmail.com> wrote:

> Thanks very much for your reply.
> Reflecting your post it now is clear to me that the (decimal) order of
> magnitude of the year
> (seconds->date (sub1 (expt 2 50))) should be around 7 or 8 (setting
> second 0 to "Thu, 01 Jan 1970 01:00:00 +0100").
> How do you know the year should be (exactly) 35680317?
> Jos
>

It comes out that way on my system (OS X):

> (seconds->date (sub1 (expt 2 50)))
(date* 3 57 13 25 9 35680317 2 267 #f -18000 0 "EST")

And I double-checked it with gregor (which doesn't use the OS for computing
dates and times):

> (require gregor)
> (posix->datetime (sub1 (expt 2 50)))
#

Note the difference in the hours field between the two answers is the
result of using local time for the former and UTC for the latter. If I pass
the additional flag to seconds->date:

> (seconds->date (sub1 (expt 2 50)) #f)
(date* 3 57 18 25 9 35680317 2 267 #f 0 0 "UTC")

... the results are the same.


-Jon




>
>
> --
> *From:* Jon Zeppieri [mailto:zeppi...@gmail.com]
> *Sent:* viernes, 19 de febrero de 2016 23:31
> *To:* Jos Koot
> *Cc:* Racket Users
> *Subject:* Re: [racket-users] second->date
>
> I'm not especially familiar with the code in question, but it looks to me
> like some time-handling code in fun.c assumes 32-bit values. I'm referring
> to this: [
> https://github.com/racket/racket/blob/50db01bf2c7c57fd5c7c662307d517ce2c29c279/racket/src/racket/src/fun.c#L9981].
>
>
> On a 64-bit system, mzlonglong should be 64 bits wide, I think, but the
> code here seems to assume 32 bits.
>
> Again, I'm really not very familiar with this code, though.
>
> (By the way, the date* you get back from (sub1 (expt 2 50)) isn't correct.
> The year should be 35680317.)
>
> -Jon
>
>
>
> On Fri, Feb 19, 2016 at 4:49 PM, Jos Koot <jos.k...@gmail.com> wrote:
>
>> The following surprises me:
>>
>> > (seconds->date (sub1 (expt 2 40)))
>> seconds->date: integer is out-of-range
>>   integer: 1099511627775
>> Nevertheless I can go further on in time:
>>
>> > (seconds->date (sub1 (expt 2 50)))
>> #(struct:date*
>>   40
>>   5
>>   11
>>   23
>>   9
>>   22520
>>   1
>>   266
>>   #t
>>   7200
>>   0
>>   "Romance Daylight Time")
>>
>> But when I go too far in future, I find myself in the past:
>>
>> > (seconds->date (sub1 (expt 2 62)))
>> #(struct:date*
>>   59
>>   59
>>   0
>>   1
>>   1
>>   1970 ---> the future seems to be in the past
>>   4
>>   0
>>   #f
>>   3600
>>   0
>>   "Romance Standard Time")
>>
>> This in the REPL of DrRacket (64 bits, Windows 7)
>> Anyone an idea what is happening here?
>> Things go well with seconds < (expt 2 31)
>> Thanks, Jos
>>
>> --
>> 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.
>>
>
>

-- 
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] second->date

2016-02-19 Thread Jon Zeppieri
Er, no. Disregard that. That'll teach me to talk about the Windows API when
I know nothing about it. Apparently, the FILETIME type is divided into two
32-bit values.

At any rate, there is a bug, but I don't know where it is.

-Jon


On Fri, Feb 19, 2016 at 5:31 PM, Jon Zeppieri <zeppi...@gmail.com> wrote:

> I'm not especially familiar with the code in question, but it looks to me
> like some time-handling code in fun.c assumes 32-bit values. I'm referring
> to this: [
> https://github.com/racket/racket/blob/50db01bf2c7c57fd5c7c662307d517ce2c29c279/racket/src/racket/src/fun.c#L9981
> ].
>
> On a 64-bit system, mzlonglong should be 64 bits wide, I think, but the
> code here seems to assume 32 bits.
>
> Again, I'm really not very familiar with this code, though.
>
> (By the way, the date* you get back from (sub1 (expt 2 50)) isn't correct.
> The year should be 35680317.)
>
> -Jon
>
>
>
> On Fri, Feb 19, 2016 at 4:49 PM, Jos Koot <jos.k...@gmail.com> wrote:
>
>> The following surprises me:
>>
>> > (seconds->date (sub1 (expt 2 40)))
>> seconds->date: integer is out-of-range
>>   integer: 1099511627775
>> Nevertheless I can go further on in time:
>>
>> > (seconds->date (sub1 (expt 2 50)))
>> #(struct:date*
>>   40
>>   5
>>   11
>>   23
>>   9
>>   22520
>>   1
>>   266
>>   #t
>>   7200
>>   0
>>   "Romance Daylight Time")
>>
>> But when I go too far in future, I find myself in the past:
>>
>> > (seconds->date (sub1 (expt 2 62)))
>> #(struct:date*
>>   59
>>   59
>>   0
>>   1
>>   1
>>   1970 ---> the future seems to be in the past
>>   4
>>   0
>>   #f
>>   3600
>>   0
>>   "Romance Standard Time")
>>
>> This in the REPL of DrRacket (64 bits, Windows 7)
>> Anyone an idea what is happening here?
>> Things go well with seconds < (expt 2 31)
>> Thanks, Jos
>>
>> --
>> 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.
>>
>
>

-- 
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] second->date

2016-02-19 Thread Jon Zeppieri
I'm not especially familiar with the code in question, but it looks to me
like some time-handling code in fun.c assumes 32-bit values. I'm referring
to this: [
https://github.com/racket/racket/blob/50db01bf2c7c57fd5c7c662307d517ce2c29c279/racket/src/racket/src/fun.c#L9981
].

On a 64-bit system, mzlonglong should be 64 bits wide, I think, but the
code here seems to assume 32 bits.

Again, I'm really not very familiar with this code, though.

(By the way, the date* you get back from (sub1 (expt 2 50)) isn't correct.
The year should be 35680317.)

-Jon



On Fri, Feb 19, 2016 at 4:49 PM, Jos Koot  wrote:

> The following surprises me:
>
> > (seconds->date (sub1 (expt 2 40)))
> seconds->date: integer is out-of-range
>   integer: 1099511627775
> Nevertheless I can go further on in time:
>
> > (seconds->date (sub1 (expt 2 50)))
> #(struct:date*
>   40
>   5
>   11
>   23
>   9
>   22520
>   1
>   266
>   #t
>   7200
>   0
>   "Romance Daylight Time")
>
> But when I go too far in future, I find myself in the past:
>
> > (seconds->date (sub1 (expt 2 62)))
> #(struct:date*
>   59
>   59
>   0
>   1
>   1
>   1970 ---> the future seems to be in the past
>   4
>   0
>   #f
>   3600
>   0
>   "Romance Standard Time")
>
> This in the REPL of DrRacket (64 bits, Windows 7)
> Anyone an idea what is happening here?
> Things go well with seconds < (expt 2 31)
> Thanks, Jos
>
> --
> 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.
>

-- 
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] assoc api

2016-02-10 Thread Jon Zeppieri
On Wed, Feb 10, 2016 at 11:02 AM, Neil Van Dyke 
wrote:

> For your example, more traditional would be `(map cons` and `cdr`. Then
> it's more clear that `assoc` returning the matched pair lets you
> distinguish a `#f` `cdr` in a match from no match found.
>
>
And dict-ref lets you do this by allowing you to provide a failure thunk.

-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] assoc api

2016-02-10 Thread Jon Zeppieri
I don't know whether there's an advantage or not, but I can say that the
behavior of assoc is inherited from Scheme and other Lisps.

I usually want the behavior you describe, so I often use dict-ref with
dealing with association lists.

-Jon


On Wed, Feb 10, 2016 at 10:55 AM, Brian Adkins 
wrote:

> Is there an advantage to having assoc return the associated list vs. the
> tail of the associated list? Wouldn't it be better for it to behave more
> like hash-ref ? Do folks typically just define their own function such as
> the following ?
>
> (define daynums (map list
>  '(sunday monday tuesday wednesday thursday friday
> saturday)
>  (range 7)))
>
> (define (aref list key)
>   (cadr (assoc key list)))
>
> (aref daynums 'wednesday)  -> 3
>
> Ruby's Array#assoc also returns the entire list, so I suppose this is just
> a historical artifact, but off the top of my head, I can't recall ever
> wanting the entire list since I already have the key I'm searching for.
>
> 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.
>

-- 
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.


<    1   2   3   >