Re: [racket-users] XML Modification

2016-12-14 Thread Lehi Toskin
> http://docs.racket-lang.org/txexpr/

Hoo-ray! splitf-xexpr is *exactly* what I needed. Thank you for your 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] Re: adding pref for rsound package

2016-12-14 Thread 'John Clements' via Racket Users

> On Dec 13, 2016, at 17:17, Robby Findler  wrote:
> 
> The phase1/phase2 stuff isn't really for preference initialization.
> You should be able to just do it when the module require'd (ie at its
> toplevl) or when the tool@ unit is invoked. Either phase would also be
> fine.

Okay, excellent.

> 
> Also, you might want to use the preference directly in the part of the
> library that doesn't depend on DrRacket (so you can run it, say, from
> the command-line), in which case you'd want to move the preferences
> initialization to that library.

Yep, already did that.
> 
> And you might want to use framework/preferences, a preferences library
> that builds on top of get-preference and adds some conveniences.

Oh, that looks nice! Many thanks!

John


> 
> Robby
> 
> 
> 
> On Tue, Dec 13, 2016 at 5:10 PM, John Clements
>  wrote:
>> The RSound package generates sounds. It generates a bunch of them at 
>> startup, and in general, there’s no way to know exactly what frame rates the 
>> machine supports. Historically, 44.1KHz has been the standard, but recently, 
>> 48K has been gaining traction, and many of my students’ machines no longer 
>> support 44.1K at all.
>> 
>> After waffling for a while on how best to solve this, I think that the right 
>> solution is to add a preference for this. I investigated the interface, and 
>> thanks to the exceptional DrRacket docs, I had no trouble implementing the 
>> preference. I have two questions/concerns:
>> 
>> 1) I notice that I don’t seem to have any other packages that have 
>> preferences, and I feel a bit funny about adding a top-level preference pane 
>> to DrRacket. Currently, my preference panel contains exactly one choice box, 
>> with the choices 44100 and 48000. Should I attach this to some other 
>> preference panel?
>> 
>> 2) Should I be adding this preference pane in the phase1 or phase2 callbacks 
>> of the tool interface, or in the base module invocation? I picked phase1, 
>> and it seems to work. Based on my reading of the phase1 and phase2 docs, it 
>> seems like… it shouldn’t matter, and maybe I should just put it in the unit 
>> invocation.
>> 
>> Finally, here’s the source code for the tool.rkt file. Any comments much 
>> appreciated!
>> 
>> Best,
>> 
>> John
>> 
>> https://github.com/jbclements/RSound/blob/forty-eight-k/rsound/tool.rkt
>> 
>> or simply as inline text:
>> 
>> #lang racket/gui
>> (require drracket/tool
>> framework)
>> 
>> (provide tool@)
>> 
>> ;; the list of permissible default frame rates.
>> ;; This is used for generation of all built-in sounds, and is the
>> ;; default for pstreams and in other places. You can change it with
>> ;; the default-frame-rate parameter, but this won't affect the sounds
>> ;; that are already generated.
>> ;; For ease of use, we limit this setting to one of a few possibilities.
>> ;; there's really no reason not to allow anything between 8K and 48K except
>> ;; that it would confuse people. I don't know whether 96K would present
>> ;; problems... it might slow down sound generation unacceptably.
>> (define LEGAL-DEFAULT-FRS '(44100 48000))
>> 
>> ;; if the existing preference is not one of the legal ones, reset to this:
>> (define RESET-FR 44100)
>> 
>> (define tool@
>>  (unit
>>(import drracket:tool^)
>>(export drracket:tool-exports^)
>>(define (phase1)
>>  (define FR-pref-from-file (get-preference 'rsound:default-frame-rate))
>>  (define FR-pref (cond [(member FR-pref-from-file LEGAL-DEFAULT-FRS)
>> FR-pref-from-file]
>>[else
>> (put-preferences '(rsound:default-frame-rate)
>>  (list RESET-FR))
>> RESET-FR]))
>>  (define FR-pref-idx (for/first ([i (in-naturals)]
>>  [fr (in-list LEGAL-DEFAULT-FRS)]
>>  #:when (= FR-pref fr))
>>i))
>>  (preferences:add-panel
>>   "RSound"
>>   (λ (parent)
>> (define vpanel
>>   (new vertical-panel% (parent parent) (alignment '(left top
>> (new choice%
>>  [label "default frame rate"]
>>  [choices (map number->string LEGAL-DEFAULT-FRS)]
>>  [parent vpanel]
>>  [selection FR-pref-idx]
>>  [callback
>>   (λ (choicebox evt)
>> (when (equal? (send evt get-event-type) 'choice)
>>   (match (send choicebox get-selection)
>> [#f (error 'choice-callbox
>>"internal error: no default frame rate 
>> selected (should be impossible?)")]
>> [n (put-preferences '(rsound:default-frame-rate)
>> (list (list-ref LEGAL-DEFAULT-FRS 
>> n)))])))])
>> vpanel)))
>>(define (phase2) (void

Re: [racket-users] Extracting the body of a fully-expanded module (with submodules)

2016-12-14 Thread Matthew Flatt
At Wed, 14 Dec 2016 18:12:52 -0800 (PST), Dupéron Georges wrote:
> Hello!
> 
> This is a follow-up to the excellent answer by Alex Knauth on StackOverflow 
> here: http://stackoverflow.com/a/38032107/324969 and this mailing-list 
> thread: 
> https://groups.google.com/forum/#!topic/racket-users/sS-pUUGp9o4
> 
> I'm trying to write a module meta-language mylang, which accepts a second 
> language to which is passes the modified body, such that:
> 
> (module foo mylang typed/racket body)
> 
> is equivalent to:
> 
> (module foo typed/racket transformed-body)
> 
> The real-world goal is to transform the fully-expanded body (e.g. add a 
> submodule, like the "doc" module added by scribble/lp2).
> 
> Alex came up with the implementation below. It puts the body into a dummy 
> module, fully expands it, and extracts the (#%plain-module-begin . mod-body), 
> patching it to require the user-provided lang. This works very well in all 
> cases except when the body contains submodules.

The problem here is somewhat related to the thread about syntax objects
in properties.

When a module expansion completes, bindings in syntax objects are
shifted so that a binding from "the module currently being expanded" is
redirected to be a binding from "this module". If you re-expand a whole
module, then "this module" is shifted back to "the module currently
being expanded"; at the end of the at re-expansion, it's shifted back
to "this module", and so on.

The problem is that you're already inside one module, the so the
expanded module's content is not shifted from "this module" to "the
module currently being expanded" as the module-body expansion
continues. That absence of a shift turns out not to matter for most
things, but submodules the second time around are instantiated as
relative to "the module currently being expanded". Meanwhile, unshifted
references remain relative to "this module".


I think you probably want something like the variant below. It's
similar to Alex's strategy, but it wraps the body in a `#%module-begin`
form, instead of `module`, so that you can use 'module-begin with
`local-expand`. That way, you stay within the same overall module
expansion. The main extra trick in the implementation is a trampoline
via `continue` to first `require` the language to get its bindings,
including `#%module-begin`.


#lang racket

;; The language definition
(module mylang racket
  (provide (rename-out [-#%module-begin #%module-begin]))
  (define-syntax (-#%module-begin stx)
(syntax-case stx ()
  [(_ lng . rest)
   (with-syntax ([#%module-begin (datum->syntax #'lng '#%module-begin)])
 #`(#%plain-module-begin
(require lng)
(continue #%module-begin . rest)))]))
  (define-syntax (continue stx)
(syntax-case stx ()
  [(_ lang-module-begin . rest)
   (let ([body-stx (local-expand
#'(lang-module-begin . rest)
'module-begin
(list))])
   ;; pattern-match on the #%plain-module-begin form to insert a require
   (syntax-case body-stx (#%plain-module-begin)
 [(#%plain-module-begin . mod-body)
  #`(begin
  .
  #,((make-syntax-introducer) #'mod-body))]))])))

;; A module using that language
(module foo (submod ".." mylang) typed/racket/base
  (module a-submod typed/racket/base
(define x 1)
(provide x))
  (require 'a-submod)
  (ann (+ x 1) Number))
(require 'foo)

-- 
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] syntax-property lost across module boundary (WAS: format-id doesn't preserve preserved?-edness of syntax-property?)

2016-12-14 Thread William J. Bowman
On Wed, Dec 14, 2016 at 03:50:28PM -0800, Alexis King wrote:
> What are the implications of this for the Types as Macros/Turnstile
...
> 
> (Obviously, I have a personal motive for asking this question, since
Based on the names of functions in my example, you'd never guess how I ran into 
this problem.
(Hint: It was implementing dependent types in Racket using Types as Macros.)

--
William J. Bowman

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


signature.asc
Description: PGP signature


[racket-users] Extracting the body of a fully-expanded module (with submodules)

2016-12-14 Thread Dupéron Georges
Hello!

This is a follow-up to the excellent answer by Alex Knauth on StackOverflow 
here: http://stackoverflow.com/a/38032107/324969 and this mailing-list thread: 
https://groups.google.com/forum/#!topic/racket-users/sS-pUUGp9o4

I'm trying to write a module meta-language mylang, which accepts a second 
language to which is passes the modified body, such that:

(module foo mylang typed/racket body)

is equivalent to:

(module foo typed/racket transformed-body)

The real-world goal is to transform the fully-expanded body (e.g. add a 
submodule, like the "doc" module added by scribble/lp2).

Alex came up with the implementation below. It puts the body into a dummy 
module, fully expands it, and extracts the (#%plain-module-begin . mod-body), 
patching it to require the user-provided lang. This works very well in all 
cases except when the body contains submodules.

In that case, I get an "require: namespace mismatch; reference to a module that 
is not available" error.

I'm rather clueless about how to solve that problem. I tried using local-expand 
with a 'module-begin context, but it then complains that x is unbound when the 
user-supplied language is typed/racket, and the error seems to be related to 
the submodules generated by TR.

Any suggestions?
Georges Dupéron




#lang racket

;; The language definition
(module mylang racket
  (provide (rename-out [-#%module-begin #%module-begin]))
  (define-syntax (-#%module-begin stx)
(syntax-case stx ()
  [(_ lng . rest)
   (with-syntax ([#%module-begin (datum->syntax #f '#%module-begin)])
 ;; put the code in a module form, and fully expand that module
 (define mod-stx
   (local-expand
#'(module ignored lng (#%module-begin . rest))
'top-level
(list)))
 ;; pattern-match on the #%plain-module-begin form to insert a require
 (syntax-case mod-stx (module #%plain-module-begin)
   [(module _ lng (#%plain-module-begin . mod-body))
#`(#%plain-module-begin
(#%require lng)
.
#,((make-syntax-introducer) #'mod-body))]))])))

;; A module using that language
(module foo (submod ".." mylang) typed/racket/base
  (module a-submod typed/racket/base
(define x 1)
(provide x))
  (require 'a-submod)
  (ann (+ x 1) Number))
(require 'foo)

-- 
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] ->i applies contract projections multiple times?

2016-12-14 Thread Scott Moore
Robby beat me to it. For a longer discussion, see Christos, Robby, Cormac and 
Matthias’ paper: http://www.ccs.neu.edu/racket/pubs/popl11-dfff.pdf on the 
difference between dependent (->d) and indy-dependent contracts (->i).

A contrived example of why this is better is:
(define/contract (foo x y)
  (->d ([x (λ (x) (y ‘evil) #t)]
        [y (-> integer? integer?)])
       [result any/c])
  void)

(foo 0 (λ (x) (+ x 1)))

> +: contract violation   !!! Whoops, but I promised to only call y with 
>integers!
  expected: number?
  given: 'evil
  argument position: 1st
  other arguments…:
vs:

(define/contract (foo x y)
  (->i ([x (y) (λ (x) (y 'evil) #t)]
        [y (-> integer? integer?)])
       [result any/c])
  void)

(foo 0 (λ (x) (+ x 1)))

foo: broke its own contract  !!! Much better :)
  promised: integer?
  produced: 'evil
  in: the 1st argument of
      the y argument of
      (->i
       ((x (y) (λ (x) (y 'evil) #t))
        (y (-> integer? integer?)))
       (result any/c))
  contract from: anonymous-module
  blaming: anonymous-module
   (assuming the contract is correct)
  at: unsaved-editor:3.18

On December 14, 2016 at 3:44:56 PM, Robby Findler (ro...@eecs.northwestern.edu) 
wrote:

I think it could be possible to avoid those printfs but only because  
the contracts used here are flat, but the implementation of ->i  
doesn't do that specialization. In the general case, the contract on  
each of the depended on arguments (x and y in this case) have to be  
applied twice, once to catch errors in the contract itself and once to  
catch errors in the body of the function. (So if you'd used  
impersonator contracts, we'd have to see multiple printouts.)  

The fact that this code prints "y" twice is related, but more  
obviously a bug to be fixed.  

#lang racket  
(define/contract f  
(->i ([x any/c]  
[y (x) (begin (printf "y\n") any/c)]  
[z (x y) (begin (printf "z\n") any/c)])  
any)  
(λ args 0))  
(f 1 2 3)  

Robby  


On Wed, Dec 14, 2016 at 5:33 PM, Alexis King  wrote:  
> This question comes from someone else on Stack Overflow, which they  
> asked here: http://stackoverflow.com/q/41144374/465378  
>  
> I think it’s likely that the people who can answer this are probably  
> only on the mailing list, though, so I figured I’d ask it here.  
>  
> Basically, the ->i contract applies contract projections more than  
> once, despite the fact that it seems unnecessary. Here’s the example  
> provided in the question:  
>  
> (define/contract (foo x y z)  
> (->i ([x (λ (x) (begin (displayln 0) #t))]  
> [y (x) (λ (y) (begin (displayln 1) #t))]  
> [z (x y) (λ (z) (begin (displayln 2) #t))])  
> any)  
> #t)  
>  
> (foo 1 2 3)  
>  
> The above example prints the following when run:  
>  
> 0  
> 0  
> 1  
> 1  
> 2  
> #t  
>  
> This indicates that values used dependently for determining other  
> contracts cause their contracts to be applied more than once. The  
> above example only uses flat contracts, but I tested with a  
> side-effectful impersonator contract and got the same result.  
>  
> After some very simple pondering, I couldn’t come up with a situation  
> in which applying the contracts more than once would be necessary,  
> and this could obviously have a performance penalty given that ->i  
> is already a fairly slow contract. Is this a bug in ->i, or is it  
> necessary or intentional behavior? If the latter, why is it necessary?  
>  
> Alexis  
>  
> --  
> 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] syntax-property lost across module boundary (WAS: format-id doesn't preserve preserved?-edness of syntax-property?)

2016-12-14 Thread Alexis King
> On Dec 14, 2016, at 7:14 AM, Matthew Flatt  wrote:
> 
> To summarize, don't try to attach syntax objects as property values
> like that. I know this advice sounds ironic, given that the original
> use of properties was for syntax-valued keys like 'origin. Properties
> like 'origin are meant to be extracted from just-expanded programs,
> though, as opposed to used in a later compilation step. At the same
> time, those uses of properties are why we can't just make
> `syntax-property` reject property values that are syntax objects.

What are the implications of this for the Types as Macros/Turnstile
stuff that Stephen and Alex have been working on, given that they
use heavily use syntax objects in syntax properties as part of
attaching type information to identifiers? Are they doing something
to work around this and/or using properties in a way that avoids
this issue? Or is it likely that they’ll run into this for programs
that span multiple modules?

(Obviously, I have a personal motive for asking this question, since
I’ve been playing with Turnstile and the techniques it uses myself.
So far I’ve been able to write programs that span multiple modules
without much issue, modulo an issue I asked about on this mailing
list a month or two back, but I’d like to know if I’m relying on
some sort of undefined behavior.)

-- 
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] ->i applies contract projections multiple times?

2016-12-14 Thread Robby Findler
I think it could be possible to avoid those printfs but only because
the contracts used here are flat, but the implementation of ->i
doesn't do that specialization. In the general case, the contract on
each of the depended on arguments (x and y in this case) have to be
applied twice, once to catch errors in the contract itself and once to
catch errors in the body of the function. (So if you'd used
impersonator contracts, we'd have to see multiple printouts.)

The fact that this code prints "y" twice is related, but more
obviously a bug to be fixed.

#lang racket
(define/contract f
  (->i ([x any/c]
[y (x) (begin (printf "y\n") any/c)]
[z (x y) (begin (printf "z\n") any/c)])
   any)
  (λ args 0))
(f 1 2 3)

Robby


On Wed, Dec 14, 2016 at 5:33 PM, Alexis King  wrote:
> This question comes from someone else on Stack Overflow, which they
> asked here: http://stackoverflow.com/q/41144374/465378
>
> I think it’s likely that the people who can answer this are probably
> only on the mailing list, though, so I figured I’d ask it here.
>
> Basically, the ->i contract applies contract projections more than
> once, despite the fact that it seems unnecessary. Here’s the example
> provided in the question:
>
>   (define/contract (foo x y z)
> (->i ([x   (λ (x) (begin (displayln 0) #t))]
>   [y (x)   (λ (y) (begin (displayln 1) #t))]
>   [z (x y) (λ (z) (begin (displayln 2) #t))])
>  any)
> #t)
>
>   (foo 1 2 3)
>
> The above example prints the following when run:
>
>   0
>   0
>   1
>   1
>   2
>   #t
>
> This indicates that values used dependently for determining other
> contracts cause their contracts to be applied more than once. The
> above example only uses flat contracts, but I tested with a
> side-effectful impersonator contract and got the same result.
>
> After some very simple pondering, I couldn’t come up with a situation
> in which applying the contracts more than once would be necessary,
> and this could obviously have a performance penalty given that ->i
> is already a fairly slow contract. Is this a bug in ->i, or is it
> necessary or intentional behavior? If the latter, why is it necessary?
>
> Alexis
>
> --
> 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] ->i applies contract projections multiple times?

2016-12-14 Thread Alexis King
This question comes from someone else on Stack Overflow, which they
asked here: http://stackoverflow.com/q/41144374/465378

I think it’s likely that the people who can answer this are probably
only on the mailing list, though, so I figured I’d ask it here.

Basically, the ->i contract applies contract projections more than
once, despite the fact that it seems unnecessary. Here’s the example
provided in the question:

  (define/contract (foo x y z)
(->i ([x   (λ (x) (begin (displayln 0) #t))]
  [y (x)   (λ (y) (begin (displayln 1) #t))]
  [z (x y) (λ (z) (begin (displayln 2) #t))])
 any)
#t)

  (foo 1 2 3)

The above example prints the following when run:

  0
  0
  1
  1
  2
  #t

This indicates that values used dependently for determining other
contracts cause their contracts to be applied more than once. The
above example only uses flat contracts, but I tested with a
side-effectful impersonator contract and got the same result.

After some very simple pondering, I couldn’t come up with a situation
in which applying the contracts more than once would be necessary,
and this could obviously have a performance penalty given that ->i
is already a fairly slow contract. Is this a bug in ->i, or is it
necessary or intentional behavior? If the latter, why is it necessary?

Alexis

-- 
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: XML Modification

2016-12-14 Thread Greg Trzeciak
On Thursday, December 15, 2016 at 12:04:23 AM UTC+1, Lehi Toskin wrote:
> I have some XML - rather, XMP data from an image - that I'd like to mess 
> around with. I've investigated the xml library and found that I can turn the 
> XML into an XEXPR so I can play around with it like that and even search 
> through it with se-path*/list, but how would I go from there to replacing 
> parts of the XEXPR? By my reckoning, I'd need to scan through the list and 
> locate the data I want and then do something like list-set, but searching 
> through an XEXPR that can have many nested sublists sounds like a nightmare 
> to program for.
> 
> I suppose I could take a look at the XML string and do a regexp-match or 
> something similar, but that seems inelegant and almost brute-force-y.

With pure XML you could use XSLT, so with SXML/xexpr you could do the same 
using SXSLT:
https://docs.racket-lang.org/sxml/sxslt.html

-- 
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] XML Modification

2016-12-14 Thread Lehi Toskin
I have some XML - rather, XMP data from an image - that I'd like to mess around 
with. I've investigated the xml library and found that I can turn the XML into 
an XEXPR so I can play around with it like that and even search through it with 
se-path*/list, but how would I go from there to replacing parts of the XEXPR? 
By my reckoning, I'd need to scan through the list and locate the data I want 
and then do something like list-set, but searching through an XEXPR that can 
have many nested sublists sounds like a nightmare to program for.

I suppose I could take a look at the XML string and do a regexp-match or 
something similar, but that seems inelegant and almost brute-force-y.

-- 
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: Good Data Structures Book?

2016-12-14 Thread Lawrence Bottorff
On Wednesday, December 14, 2016 at 12:19:51 PM UTC-5, Prabhakar Ragde wrote:
> 
> I am developing such a course for a spring term (May-August) offering at 
> the University of Waterloo (though it will probably use OCaml). There 
> does not appear to be an ideal textbook; I plan to synthesize materials. 
> There are FP books which cover some of the material in various 
> languages: Simon Thompson's Haskell book, Algorithms by Rabhi and 
> Lapalme (also Haskell), Larry Paulson's ML book. (In my opinion, Okasaki 
> and Bird are too advanced for a first DS course.) Mark Allen Weiss's DS 
> book in C is the best conventional book I have found; it is not afraid 
> of recursion.
> 
> One issue is that an early FP approach may well cover some topics from a 
> typical DS course, since it is possible to do so earlier. Examples from 
> my own experience include various sorting algorithms, O-notation and 
> algorithm analysis, various heap implementations of priority queues, 
> treaps, AVL trees, RB trees, AA trees, tries, and KMP text search. I 
> have covered these in various incarnations of first-year Racket courses 
> (not all at once).
> 
> I'd be happy to consult if you are considering developing a course. --PR

Yes, I have the Paulson book "ML for the Working Programmer," which mixes in 
some data structure, but nothing so thorough as Weiss. Then there is Okasaki's 
"Purely Functional Data Structures," which lives solely in the purely 
functional land of ML and Haskell and can't really be brought out very easily 
or so it seems to me. Anyway, it was a dissertation, which is inappropriate for 
undergrads. The other books mentioned aren't for weak of heart grad students, 
let alone undergrads. I find it ironic that I can search Racket docs on 
virtually any data structure and find a library ready and waiting. Maybe 
whoever did all those libraries should be volunteered into writing a textbook? 
(Laughter.) In general, I'm sure that between Weiss and Okasaki's "Purely 
Functional Data Structures" would be a nuanced Racket/TR way of doing things 
(macros, combinators, etc.). I'm personally not that good at Racket to know the 
"Enlightened Way," but it would be a good thing to have, no doubt.

-- 
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] syntax-property lost across module boundary (WAS: format-id doesn't preserve preserved?-edness of syntax-property?)

2016-12-14 Thread Matthew Flatt
At Wed, 14 Dec 2016 10:43:34 -0700, Matthew Flatt wrote:
> But right now, as Sam well knows

I'd like to clarify that this is because Sam has been very helpful in
making things better --- not that he's been asking for new things.

-- 
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] syntax-property lost across module boundary (WAS: format-id doesn't preserve preserved?-edness of syntax-property?)

2016-12-14 Thread Matthew Flatt
Yes, it's obviously easier to implement this new feature with the new
expander.

But right now, as Sam well knows, I'm open to patches only as long as
they make things no slower and no bigger. :) The current implementation
is reliably within a factor of 2 of the old one, but we're still
working to close the gap.

At Wed, 14 Dec 2016 11:09:12 -0500, Matthias Felleisen wrote:
> 
> > On Dec 14, 2016, at 10:23 AM, Sam Tobin-Hochstadt  
> wrote:
> > 
> > On Wed, Dec 14, 2016 at 10:14 AM, Matthew Flatt  wrote:
> >> More generally, changes to the scope of a
> >> syntax object are not propagated to property values that happen to be
> >> themselves syntax objects. When you put a syntax object into a
> >> property, then you get whatever that syntax object meant at the time it
> >> was attached as a property.
> > 
> > This is a limitation of syntax properties that I've long had to work
> > around in Typed Racket as well. Are there fundamental reasons why we
> > couldn't have a kind of syntax property that scopes propaged to? Would
> > this be something that would be easier to implement in the new
> > expander?
> > 
> > Sam
> 
> 
> I can’t believe I fell for this again. Ryan has explained this more than once 
> to me . .  . and yet. In this spirit, I support Sam’s question  :-) 
> 
> -- 
> 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] Good Data Structures Book?

2016-12-14 Thread 'John Clements' via Racket Users

> On Dec 14, 2016, at 9:19 AM, Prabhakar Ragde  wrote:
> 
> Lawrence Bottorff wrote:
> 
>> Can someone suggest a good text for data structures that would
>> compatible with Racket? All I see are treatments using C/C++, Java,
>> Python, i.e., the usual suspects. Or, how do you people at
>> Racket-friendly/based universities teach undergrad data structures?
> 
> I am developing such a course for a spring term (May-August) offering at the 
> University of Waterloo (though it will probably use OCaml). There does not 
> appear to be an ideal textbook; I plan to synthesize materials. There are FP 
> books which cover some of the material in various languages: Simon Thompson's 
> Haskell book, Algorithms by Rabhi and Lapalme (also Haskell), Larry Paulson's 
> ML book. (In my opinion, Okasaki and Bird are too advanced for a first DS 
> course.) Mark Allen Weiss's DS book in C is the best conventional book I have 
> found; it is not afraid of recursion.
> 
> One issue is that an early FP approach may well cover some topics from a 
> typical DS course, since it is possible to do so earlier. Examples from my 
> own experience include various sorting algorithms, O-notation and algorithm 
> analysis, various heap implementations of priority queues, treaps, AVL trees, 
> RB trees, AA trees, tries, and KMP text search. I have covered these in 
> various incarnations of first-year Racket courses (not all at once).
> 
> I'd be happy to consult if you are considering developing a course. —PR

I’m hesitant to chime in because my situation is a bit different, but I’m 
trying to make my department happy (appeasement, I know) by teaching a 
late-spring-of-first-year data structures in Python. We will be trying to stay 
within idiomatic Python while building on the design recipe, not an easy task.

I’m going to take a look at the books you mention, and I’d very much like to 
hear about progress you make on your class.

Many thanks!

John Clements



-- 
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] Good Data Structures Book?

2016-12-14 Thread Prabhakar Ragde

Lawrence Bottorff wrote:


Can someone suggest a good text for data structures that would
compatible with Racket? All I see are treatments using C/C++, Java,
Python, i.e., the usual suspects. Or, how do you people at
Racket-friendly/based universities teach undergrad data structures?


I am developing such a course for a spring term (May-August) offering at 
the University of Waterloo (though it will probably use OCaml). There 
does not appear to be an ideal textbook; I plan to synthesize materials. 
There are FP books which cover some of the material in various 
languages: Simon Thompson's Haskell book, Algorithms by Rabhi and 
Lapalme (also Haskell), Larry Paulson's ML book. (In my opinion, Okasaki 
and Bird are too advanced for a first DS course.) Mark Allen Weiss's DS 
book in C is the best conventional book I have found; it is not afraid 
of recursion.


One issue is that an early FP approach may well cover some topics from a 
typical DS course, since it is possible to do so earlier. Examples from 
my own experience include various sorting algorithms, O-notation and 
algorithm analysis, various heap implementations of priority queues, 
treaps, AVL trees, RB trees, AA trees, tries, and KMP text search. I 
have covered these in various incarnations of first-year Racket courses 
(not all at once).


I'd be happy to consult if you are considering developing a course. --PR

--
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] syntax-property lost across module boundary (WAS: format-id doesn't preserve preserved?-edness of syntax-property?)

2016-12-14 Thread Matthias Felleisen

> On Dec 14, 2016, at 10:23 AM, Sam Tobin-Hochstadt  
> wrote:
> 
> On Wed, Dec 14, 2016 at 10:14 AM, Matthew Flatt  wrote:
>> More generally, changes to the scope of a
>> syntax object are not propagated to property values that happen to be
>> themselves syntax objects. When you put a syntax object into a
>> property, then you get whatever that syntax object meant at the time it
>> was attached as a property.
> 
> This is a limitation of syntax properties that I've long had to work
> around in Typed Racket as well. Are there fundamental reasons why we
> couldn't have a kind of syntax property that scopes propaged to? Would
> this be something that would be easier to implement in the new
> expander?
> 
> Sam


I can’t believe I fell for this again. Ryan has explained this more than once 
to me . .  . and yet. In this spirit, I support Sam’s question  :-) 

-- 
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] syntax-property lost across module boundary (WAS: format-id doesn't preserve preserved?-edness of syntax-property?)

2016-12-14 Thread Sam Tobin-Hochstadt
On Wed, Dec 14, 2016 at 10:14 AM, Matthew Flatt  wrote:
> More generally, changes to the scope of a
> syntax object are not propagated to property values that happen to be
> themselves syntax objects. When you put a syntax object into a
> property, then you get whatever that syntax object meant at the time it
> was attached as a property.

This is a limitation of syntax properties that I've long had to work
around in Typed Racket as well. Are there fundamental reasons why we
couldn't have a kind of syntax property that scopes propaged to? Would
this be something that would be easier to implement in the new
expander?

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] syntax-property lost across module boundary (WAS: format-id doesn't preserve preserved?-edness of syntax-property?)

2016-12-14 Thread Matthew Flatt
I think there are two problems in this example.


The first problem is that preserved syntax properties were not actually
preserved in bytecode for a syntax object that has no source location.
(I'm assuming that Alexis's tests were run in DrRacket in it's default
mode of compiling bytecode for `require`d files.) I'll push a repair
for that bug.


The second problem is that syntax objects as property values don't work
the way that you want. That limitation is why, even with the
property-presevation bug fixed, the `free-identifier=?` test fails.
Unfortunately, that's a limitation of syntax objects and properties
that's difficult to resolve.

To explain a little more, consider the program

 https://gist.github.com/mflatt/d569d8f3a89e6815cf18df26adc11053

For now, look at just the `property` submodule. The
`quote-syntax/add-example-property` macro is like `quote-syntax`,
except that it adds an 'example property that holds the current time at
compile time.

An expression like

 (syntax-property (quote-syntax/add-example-property id) 'example)

accesses that compile-time value at run time. If you compile the
program to bytecode, the value shown by running the module later still
reports the time that the module was compiled.

Now consider the enclosing module, which uses the `property` submodule
and accesses the time for both a freshly quoted term and the value of
`id` as exported by the submodule:

 (require 'property)
 (syntax-property (quote-syntax/add-example-property new-id) 'example)
 (syntax-property id 'example)

I think you won't be too surprised that the freshly quoted identifier
has a newer time than the one reported for `id`. Even though both
values were obtained from the same `compile-time` variable, each module
compilation (submodule and enclosing module) gets a fresh instance of
`compile-time`.


In "format-id1.rkt", instead of `compile-time` bound to a timestamp,
you have a quoted syntax object that you can image being implicitly
lifted as

  (define-for-syntax compile-time #'id^)

In much the same way that `(current-inexact-milliseconds)` in

  (define-for-syntax compile-time (current-inexact-milliseconds))

produces a different result for each subsequent compile-time use of the
modules, `#'id^` produces a different syntax object depending on how
its enclosing module is instantiated. Imagine taking the compiled
bytecode, saving it in two places, and loading it as a module from each
place; the `#'id` evaluations for the copies will produce identifiers
that claim to be from different modules relative to the filesystem.

So, here's the limitation: the implicit lifting that happens for a
quoted syntax object, which enables a kind of re-evaluation of that
syntax object in each module instance, doesn't happen for
syntax-property values. More generally, changes to the scope of a
syntax object are not propagated to property values that happen to be
themselves syntax objects. When you put a syntax object into a
property, then you get whatever that syntax object meant at the time it
was attached as a property.

That might still sound ok for your case, because you compile and use
"format-id1.rkt" in-place. Still, the information attached to `#'id^`
changes. While compiling the module, the attached binding information
says "the current module being compiled". When compiling
"format-id2.rkt", the attached binding information for that `#'id^`
says "format-id1.rkt".


To summarize, don't try to attach syntax objects as property values
like that. I know this advice sounds ironic, given that the original
use of properties was for syntax-valued keys like 'origin. Properties
like 'origin are meant to be extracted from just-expanded programs,
though, as opposed to used in a later compilation step. At the same
time, those uses of properties are why we can't just make
`syntax-property` reject property values that are syntax objects.


At Tue, 13 Dec 2016 14:16:49 -0800, Alexis King wrote:
> > On Dec 13, 2016, at 11:23 AM, 'William J. Bowman' via Racket Users
> >  wrote:
> > 
> > Notice that #'x is not the same identifier as x, and thus does not
> > have the same syntax-properties.
> 
> I’m not convinced this is correct.
> 
> If you insert println statements in the body of define^, inside the
> with-syntax block, you get the following:
> 
>   (println (syntax-property #'x 'definition))
>   (println (syntax-property-preserved? #'x 'definition))
> 
>   ; => #
>   ; => #t
> 
> The syntax properties are definitely maintained in templates used
> by `syntax`.
> 
> > Why does this issue only comes up across a file boundary? I suspect
> > this has to do with the behavior of make-rename-transformer. Since
> > #'x was not getting 'not-free-identifier=? correctly,
> > make-rename-transformer was optimizing this away, although I thought
> > I was preventing that.
> 
> This is more interesting, and it was my first instinct, too. For
> that reason, I replaced uses of make-rename-transformer with uses

Re: [racket-users] Package catalog - can't connect

2016-12-14 Thread P. Baillet
Hello group,

I have inspected things.

And upon careful println debugging (around mzssl.rkt:760), ended up running:

mkdir -p home/mflatt/build/bl/l64/dest/ssl/
wget -O /home/mflatt/build/bl/l64/dest/ssl/cert.pem 
http://curl.haxx.se/ca/cacert.pem

Which actually fixed the raco install. I guess the certificates are not read 
from the correct path.

More debug show this:

root@5e50a7d9f676:/usr/share/racket# strings /usr/lib/racket/libcrypto.so.1.0.0 
 | grep mflatt
OPENSSLDIR: "/home/mflatt/build/bl/l64/dest/ssl"
/home/mflatt/build/bl/l64/dest/lib/engines
/home/mflatt/build/bl/l64/dest/ssl/private
/home/mflatt/build/bl/l64/dest/ssl
/home/mflatt/build/bl/l64/dest/ssl/certs
/home/mflatt/build/bl/l64/dest/ssl/cert.pem

Another fix if you have certificates in /etc/ssl/certs :

mkdir -p /home/mflatt/build/bl/l64/dest/ssl
root@5e50a7d9f676:/usr/share/racket# ln -s /etc/ssl/certs/ 
/home/mflatt/build/bl/l64/dest/ssl/certs

The bug concerns racket-6.6-x86_64-linux-natipkg.sh and no longer exists in 
racket-6.7-x86_64-linux.sh .


On Wednesday, November 2, 2016 at 11:24:52 PM UTC+1, P. Baillet wrote:
> Hello racketeers,
> 
> I have the same issue on a Docker based Racket install:
> 
> FROM ubuntu:14.04
> 
> RUN apt-get update
> RUN apt-get install -y curl
> WORKDIR /tmp/
> RUN curl -t fsSL 
> http://mirror.racket-lang.org/installers/6.6/racket-6.6-x86_64-linux-natipkg.sh
>  > racket.sh
> RUN echo "yes\n1\n" | /bin/bash racket.sh
> RUN rm racket.sh
> RUN raco pkg install elasticsearch
> 
> 
> Resolving "elasticsearch" via 
> https://download.racket-lang.org/releases/6.6/catalog/
> ssl-connect: connect failed (error:14090086:SSL 
> routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed)
>   context...:
>/usr/share/racket/collects/openssl/mzssl.rkt:1442:8: loop
>/usr/share/racket/collects/openssl/../racket/private/more-scheme.rkt:261:28
>
> /usr/share/racket/collects/openssl/../racket/contract/private/arrow-val-first.rkt:306:25
>/usr/share/racket/collects/net/http-client.rkt:235:0
>
> /usr/share/racket/collects/racket/contract/private/arrow-val-first.rkt:397:3
>/usr/share/racket/collects/net/url.rkt:144:0: http://getpost-impure-port
>/usr/share/racket/collects/net/url.rkt:251:2: redirection-loop
>
> /usr/share/racket/collects/racket/contract/private/arrow-val-first.rkt:397:3
>/usr/share/racket/collects/pkg/private/network.rkt:59:3
>/usr/share/racket/collects/pkg/private/catalog.rkt:218:0: read-from-server
>/usr/share/racket/collects/pkg/private/catalog.rkt:138:9: for-loop
>/usr/share/racket/collects/pkg/private/catalog.rkt:135:2: lookup-normally
>
> /usr/share/racket/collects/pkg/private/../../racket/private/more-scheme.rkt:261:28
>/usr/share/racket/collects/pkg/private/prefetch.rkt:128:2
>/usr/share/racket/collects/pkg/private/catalog.rkt:132:0: 
> package-catalog-lookup9
>/usr/share/racket/collects/pkg/private/catalog.rkt:200:0: 
> package-catalog-lookup-source19
> 
> I've tried upgrading the distro before, but without any luck...
> 
> 
> On Wednesday, April 20, 2016 at 1:29:47 AM UTC+2, Jordan Johnson wrote:
> > At Mon, 18 Apr 2016 14:32:20 -0700, Jordan Johnson wrote:
> > ssl-connect: connect failed (error:14090086:SSL 
> > routines:ssl3_get_server_certificate:certificate verify failed)
> >  context…: [stack trace follows]
> > 
> > I've seen these kinds of problems where the set of trusted certificates
> > had not been updated recently enough. Maybe there's an update for the
> > "ca-certificates" package for your installation?
> > 
> > 
> > 
> > Possibly; I may have to kick this over to my ISP’s support, since it’s a 
> > managed VPS on which I can’t install packages system-wide.
> > You could also try setting the `PLT_PKG_SSL_NO_VERIFY` environment
> > variable. As a workaround, that's a last resort, but it might help
> > clarify whether it issue is with the set of trusted root certificates.
> > 
> > 
> > 
> > Ah! OK, I tried that, and got:
> > ssl-connect: connect failed (error:14090086:SSL 
> > routines:ssl3_get_server_certificate:certificate verify failed)
> > 
> > 
> > Same error, suggesting the problem isn’t failure to verify. Is there any 
> > way to get more info from raco about the cause of failure? I looked for a 
> > “verbose” option to raco pkg install, but AFAICT there is none.
> > 
> > 
> > Best,
> > jmj

-- 
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] Good Data Structures Book?

2016-12-14 Thread WarGrey Gyoudmon Ju
"Pearls of Functional Algorithm Design"
https://www.amazon.com/Pearls-Functional-Algorithm-Design-Richard/dp/0521513383/ref=sr_1_1

The functional "programming pearls" in Haskell, but the author prefers the
term "algorithm design".


On Wed, Dec 14, 2016 at 2:48 AM, Ben Greenman 
wrote:

> "Purely Functional Data Structures"
> https://www.amazon.com/Purely-Functional-Structures-Chris-
> Okasaki/dp/0521663504
>
> On Tue, Dec 13, 2016 at 1:22 PM, Lawrence Bottorff 
> wrote:
>
>> Can someone suggest a good text for data structures that would compatible
>> with Racket? All I see are treatments using C/C++, Java, Python, i.e., the
>> usual suspects. Or, how do you people at Racket-friendly/based universities
>> teach undergrad data structures?
>>
>> --
>> 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.