Re: [racket-users] Why are SQLITE queries so slow?

2015-03-26 Thread Jens Axel Søgaard
How did you time the queries?

/Jens Axel


2015-03-25 15:03 GMT+01:00 Renaud rgomb...@essentiel.net:
 Hi,

 I'm new to Racket, and i would like to know why sqlite queries are so slow in 
 my test program.

 This program imports some data from a text file into a simple sqlite DB. It 
 takes 35s with the INSERT queries and 5-6s without them.

 I've done the same thing with other languages, all do far better. For example 
 with perl the same code runs in 8s with the queries, and 2-3s with them.

 I know that startup and regex are (reasonably ?) slower in racket, but 
 queries seems to be very slow.

 Am i doing somethin wrong?

 Thanks for your help.


 test done by swapping the commented line with the next. Code :
 -
 #!/usr/bin/env racket

 #lang racket/base
 (require racket/list racket/string db/base db/sqlite3)

 (define DBFILE database.rkt.sql)
 (define rx #rx[~^]+)
 (define sdb #f)

 (define (openDatas)
 (unless sdb (set! sdb (sqlite3-connect #:database DBFILE

 (define (importDatas)
 (when (file-exists? DBFILE) (delete-file DBFILE))
 (set! sdb (sqlite3-connect #:database DBFILE #:mode 'create))
 (start-transaction sdb)
 (query-exec sdb CREATE TABLE groups (fam INTEGER, name STRING , PRIMARY 
 KEY (fam)))
 (query-exec sdb CREATE TABLE foods (alim INTEGER, fam INTEGER, name 
 STRING , PRIMARY KEY (alim)))
 (query-exec sdb CREATE TABLE nutrients (nutr INTEGER, unit STRING, short 
 STRING, name STRING , PRIMARY KEY (nutr)))
 (query-exec sdb CREATE TABLE contents (alim INTEGER, nutr INTEGER, val 
 FLOAT , PRIMARY KEY (alim, nutr)))
 (process-file FD_GROUP.txt groups2)
 (process-file FOOD_DES.txt foods 3)
 (process-file NUTR_DEF.txt nutrients 4)
 (process-file NUT_DATA.txt contents  3)
 (commit-transaction sdb))

 (define (process-file fname table nb)
 (define Q (prepare sdb (string-append INSERT INTO  table  VALUES ( 
 (string-join (for/list ([x nb]) ?) ,) 
 (call-with-input-file fname (lambda (file)
 (for ([line (in-port read-line file)])
 ;(bind-prepared-statement Q (take (regexp-split rx line 1) 
 nb))
 (query-exec sdb (bind-prepared-statement Q (take (regexp-split rx 
 line 1) nb)))


 (importDatas)
 -

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



-- 
--
Jens Axel Søgaard

-- 
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 are SQLITE queries so slow?

2015-03-26 Thread Jens Axel Søgaard
Did you subtract the startup cost of Racket to get the time of the queries?

/Jens Axel


2015-03-26 19:29 GMT+01:00 Renaud renaud.gomb...@gmail.com:
 Le jeudi 26 mars 2015 19:21:11 UTC+1, Jens Axel Søgaard a écrit :
 How did you time the queries?

 /Jens Axel


 2015-03-25 15:03 GMT+01:00 Renaud renaud:
  Hi,
 
  I'm new to Racket, and i would like to know why sqlite queries are so slow 
  in my test program.
 
  This program imports some data from a text file into a simple sqlite DB. 
  It takes 35s with the INSERT queries and 5-6s without them.
 
  I've done the same thing with other languages, all do far better. For 
  example with perl the same code runs in 8s with the queries, and 2-3s with 
  them.
 
  I know that startup and regex are (reasonably ?) slower in racket, but 
  queries seems to be very slow.
 
  Am i doing somethin wrong?
 
  Thanks for your help.
 
 
  test done by swapping the commented line with the next. Code :
  -
  #!/usr/bin/env racket
 
  #lang racket/base
  (require racket/list racket/string db/base db/sqlite3)
 
  (define DBFILE database.rkt.sql)
  (define rx #rx[~^]+)
  (define sdb #f)
 
  (define (openDatas)
  (unless sdb (set! sdb (sqlite3-connect #:database DBFILE
 
  (define (importDatas)
  (when (file-exists? DBFILE) (delete-file DBFILE))
  (set! sdb (sqlite3-connect #:database DBFILE #:mode 'create))
  (start-transaction sdb)
  (query-exec sdb CREATE TABLE groups (fam INTEGER, name STRING , 
  PRIMARY KEY (fam)))
  (query-exec sdb CREATE TABLE foods (alim INTEGER, fam INTEGER, name 
  STRING , PRIMARY KEY (alim)))
  (query-exec sdb CREATE TABLE nutrients (nutr INTEGER, unit STRING, 
  short STRING, name STRING , PRIMARY KEY (nutr)))
  (query-exec sdb CREATE TABLE contents (alim INTEGER, nutr INTEGER, 
  val FLOAT , PRIMARY KEY (alim, nutr)))
  (process-file FD_GROUP.txt groups2)
  (process-file FOOD_DES.txt foods 3)
  (process-file NUTR_DEF.txt nutrients 4)
  (process-file NUT_DATA.txt contents  3)
  (commit-transaction sdb))
 
  (define (process-file fname table nb)
  (define Q (prepare sdb (string-append INSERT INTO  table  VALUES ( 
  (string-join (for/list ([x nb]) ?) ,) 
  (call-with-input-file fname (lambda (file)
  (for ([line (in-port read-line file)])
  ;(bind-prepared-statement Q (take (regexp-split rx line 1) 
  nb))
  (query-exec sdb (bind-prepared-statement Q (take (regexp-split 
  rx line 1) nb)))
 
 
  (importDatas)
  -

 --
 Jens Axel Søgaard

 Hi Jens Axel,

 I just used time ./my-script.rkt with the given code, then after swapping 
 the comment near the bottom :

 ;(bind-prepared-statement Q (take (regexp-split rx line 1) 
 nb))
 (query-exec sdb (bind-prepared-statement Q (take (regexp-split rx 
 line 1) nb)))

 vs.

 (bind-prepared-statement Q (take (regexp-split rx line 1) nb))
 ;(query-exec sdb (bind-prepared-statement Q (take (regexp-split 
 rx line 1) nb)))

 Crude... i know...



-- 
--
Jens Axel Søgaard

-- 
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] ANN: Gregor, a date and time library

2015-03-26 Thread Jens Axel Søgaard
2015-03-26 22:30 GMT+01:00 Jon Zeppieri zeppi...@gmail.com:
 On Thu, Mar 26, 2015 at 5:27 PM, Robby Findler

  Would 3 weeks and 40 hours always be a precise number of
 seconds?

 Robby

What about leap seconds?

/Jens Axel

-- 
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 are SQLITE queries so slow?

2015-03-26 Thread Jens Axel Søgaard
Did you subtract the startup cost of Racket to get the time of the queries?

/Jens Axel


2015-03-26 19:29 GMT+01:00 Renaud renaud.gomb...@gmail.com:
 Le jeudi 26 mars 2015 19:21:11 UTC+1, Jens Axel Søgaard a écrit :
 How did you time the queries?

 /Jens Axel


 2015-03-25 15:03 GMT+01:00 Renaud renaud:
  Hi,
 
  I'm new to Racket, and i would like to know why sqlite queries are so slow 
  in my test program.
 
  This program imports some data from a text file into a simple sqlite DB. 
  It takes 35s with the INSERT queries and 5-6s without them.
 
  I've done the same thing with other languages, all do far better. For 
  example with perl the same code runs in 8s with the queries, and 2-3s with 
  them.
 
  I know that startup and regex are (reasonably ?) slower in racket, but 
  queries seems to be very slow.
 
  Am i doing somethin wrong?
 
  Thanks for your help.
 
 
  test done by swapping the commented line with the next. Code :
  -
  #!/usr/bin/env racket
 
  #lang racket/base
  (require racket/list racket/string db/base db/sqlite3)
 
  (define DBFILE database.rkt.sql)
  (define rx #rx[~^]+)
  (define sdb #f)
 
  (define (openDatas)
  (unless sdb (set! sdb (sqlite3-connect #:database DBFILE
 
  (define (importDatas)
  (when (file-exists? DBFILE) (delete-file DBFILE))
  (set! sdb (sqlite3-connect #:database DBFILE #:mode 'create))
  (start-transaction sdb)
  (query-exec sdb CREATE TABLE groups (fam INTEGER, name STRING , 
  PRIMARY KEY (fam)))
  (query-exec sdb CREATE TABLE foods (alim INTEGER, fam INTEGER, name 
  STRING , PRIMARY KEY (alim)))
  (query-exec sdb CREATE TABLE nutrients (nutr INTEGER, unit STRING, 
  short STRING, name STRING , PRIMARY KEY (nutr)))
  (query-exec sdb CREATE TABLE contents (alim INTEGER, nutr INTEGER, 
  val FLOAT , PRIMARY KEY (alim, nutr)))
  (process-file FD_GROUP.txt groups2)
  (process-file FOOD_DES.txt foods 3)
  (process-file NUTR_DEF.txt nutrients 4)
  (process-file NUT_DATA.txt contents  3)
  (commit-transaction sdb))
 
  (define (process-file fname table nb)
  (define Q (prepare sdb (string-append INSERT INTO  table  VALUES ( 
  (string-join (for/list ([x nb]) ?) ,) 
  (call-with-input-file fname (lambda (file)
  (for ([line (in-port read-line file)])
  ;(bind-prepared-statement Q (take (regexp-split rx line 1) 
  nb))
  (query-exec sdb (bind-prepared-statement Q (take (regexp-split 
  rx line 1) nb)))
 
 
  (importDatas)
  -

 --
 Jens Axel Søgaard

 Hi Jens Axel,

 I just used time ./my-script.rkt with the given code, then after swapping 
 the comment near the bottom :

 ;(bind-prepared-statement Q (take (regexp-split rx line 1) 
 nb))
 (query-exec sdb (bind-prepared-statement Q (take (regexp-split rx 
 line 1) nb)))

 vs.

 (bind-prepared-statement Q (take (regexp-split rx line 1) nb))
 ;(query-exec sdb (bind-prepared-statement Q (take (regexp-split 
 rx line 1) nb)))

 Crude... i know...



-- 
--
Jens Axel Søgaard

-- 
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] infix notation embedded in Racket

2015-04-25 Thread Jens Axel Søgaard
 2015-04-24 14:44 GMT+02:00 Jens Axel Søgaard jensa...@soegaard.net:

 The arrows disappear when I use the at-exp syntax:  @${b^2-4*a*x}.
 I am not sure why. Anyone?


Thanks to Alexander for submitting a fix.

/Jens Axel

-- 
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] infix notation embedded in Racket

2015-04-25 Thread Jens Axel Søgaard
2015-04-24 14:44 GMT+02:00 Jens Axel Søgaard jensa...@soegaard.net:


 The planet package took a *very* long time to install, so I intend to
 upload a version to pkg.racket-lang.org.


The infix package is now available through pkg.racket-lang.org.

/Jens Axel

-- 
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: infix notation embedded in Racket

2015-04-25 Thread Jens Axel Søgaard
2015-04-24 18:32 GMT+02:00 Jens Axel Søgaard jensa...@soegaard.net:



 2015-04-24 18:25 GMT+02:00 Jos Koot jos.k...@gmail.com:

  Hi Jens Axel,

 Thanks for replying and explaining.

 Can you discriminate between a+b and |a+b| or a|+|b?

 When I get around to adding |...| identifiers to the lexer, it will work
 like this:

   a+b   will be parsed as (+ a b)
   |a+b|  as a+b(a single identifier)
   a|+|b  will be passed as (+ a b)


I forgot to mention that the infix reader already reads  foo_bar as foo-bar.
I.e. the most common symbols are easily accessible already.

/Jens Axel

-- 
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] infix notation embedded in Racket

2015-04-25 Thread Jens Axel Søgaard
2015-04-24 14:44 GMT+02:00 Jens Axel Søgaard jensa...@soegaard.net:

 The arrows disappear when I use the at-exp syntax:  @${b^2-4*a*x}.
 I am not sure why. Anyone?


I haven't figured it out yet, but it seems to have worked at some point.

I have found this:


(define-syntax ($ stx) (syntax-case stx () [(_ item ...) (let* ([from-at?
(syntax-property stx 'scribble)]) (if from-at? ; reintroduce the original
(discarded) indentation (with-syntax ([(item ...) (let loop ([items
(syntax-list #'(item ...))]) (if (null? items) '() (let* ([fst (car items)]
[prop (syntax-property fst 'scribble)] [rst (loop (cdr items))]) (cond
[(eq? prop 'indentation) rst] [(not (and (pair? prop) (eq? (car prop)
'newline))) (cons fst rst)] [else (cons (datum-syntax fst (cadr prop) fst)
rst)]]) #'($$ item ...)) #'($$ item ...)))]))

-- 
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] infix notation embedded in Racket

2015-04-24 Thread Jens Axel Søgaard
2015-04-24 0:18 GMT+02:00 Alexander D. Knauth alexan...@knauth.org:


 What’s wrong with at-exp though?
 I personally don’t like (planet soegaard/infix) as much mostly because the
 other options have the benefit of working with DrRacket features such as
 check-syntax arrows and blue-boxes, but that’s just because DrRacket is
 awesome, not because at-exp is bad.


As it turns out, it is at-exp that are at fault.

The screen shot below show that arrows and renaming works when using the
infix packages with the syntax:
  ($ b^2-4*a*x)

Note that it works even for identifiers inside the string.

The arrows disappear when I use the at-exp syntax:  @${b^2-4*a*x}.
I am not sure why. Anyone?

The planet package took a *very* long time to install, so I intend to
upload a version to pkg.racket-lang.org.

/Jens Axel

-- 
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: infix notation embedded in Racket

2015-04-24 Thread Jens Axel Søgaard
2015-04-23 18:51 GMT+02:00 Jos Koot jos.k...@gmail.com:

  Long ago I made various parsers (most of them in Fortran or assembler)
 for expressions with infix notation. I always used push-down automata with
 two or more stacks. Now I am playing with macros in Racket that allow
 infix notation embedded in Racket without explicitly using push-down
 automata. However, I encounter a contradiction in my desires as explained
 below. I have looked at 'Infix expressions for PLT Scheme' available in
 planet and made by Jens Axel Søgaard. In his approach a+b is evaluated as
 though written as (+ a b). However:

 #lang at-exp scheme
 (require (planet soegaard/infix))
 (define a+b 4)
 (define a 1) (define b 2)
 @${a+b}  ; evaluates to 3

 A Racket variable can contain characters such as +, -, * etc.
 This makes @${a+b} confusing
 (not necessarily ambiguous, though, depending on syntax and semantics.


The rule is that operators such as +,-, * behave as operators in infix
expressions.
My intention was to support identifiers with, say, - in them using bar
notation as in |foo-bar|
but I never got around to add them.

If one want to allow the usual operators in identifiers without a quoting
mechanism,
then spaces are need to separate operators and identifiers - which may or
may not
fell annoying.

/Jens Axel

-- 
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: infix notation embedded in Racket

2015-04-24 Thread Jens Axel Søgaard
2015-04-24 18:25 GMT+02:00 Jos Koot jos.k...@gmail.com:

  Hi Jens Axel,

 Thanks for replying and explaining.

 Can you discriminate between a+b and |a+b| or a|+|b?

 When I get around to adding |...| identifiers to the lexer, it will work
like this:

  a+b   will be parsed as (+ a b)
  |a+b|  as a+b(a single identifier)
  a|+|b  will be passed as (+ a b)

I don't see how without using a language with it's own key-binding for |.


I am not following. The $ macro can be required into any language?.

/Jens Axel

-- 
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] Rosetta Code: Level 1st (that's FIRST) with TCL

2015-04-29 Thread Jens Axel Søgaard
Great news!

Worth a blog post to follow up on:

http://blog.racket-lang.org/2013/03/200_25.html
http://blog.racket-lang.org/2014/11/800.html

/Jens Axel



2015-04-29 1:38 GMT+02:00 Tim Brown t...@cityc.co.uk:

 Folks,

 I've just done a quick burst of cherry picking tasks on Rosetta
 Code (www.rosettacode.org). I took a quick look at:
 * http://rosettacode.org/wiki/Category:Tcl
 and
 *  http://rosettacode.org/wiki/Category:Racket

 And they both have the line:
 The following 845 pages are in this category, out of 845 total. 

 I *think* that means that both Tcl and Racket have 845 tasks impemented,
 but short of walking down a printout with a pen (and it's far to late to
 be doing that) -- I do believe that Tcl and Racket are now jointly the
 most popular programming languages on Rosetta Code.

 WELL DONE AND THANKS TO EVERYONE WHO HAS CONTRIBUTED (especially Racket)
 CODE ONTO ROSETTA CODE!

 And many, many thanks to the Racket team for producing a language which
 is now demonstrably as competent as any. (Although we all knew that before
 anyway, didn't we?)

 Tim

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Rosetta Code: Level 1st (that's FIRST) with TCL

2015-04-29 Thread Jens Axel Søgaard
Perhaps one (you) could make a task demonstrating how to make new binding
constructs?

/Jens Axel


2015-04-29 12:44 GMT+02:00 Stephen De Gabrielle spdegabrie...@gmail.com:

 Are there any tasks suitable for Rosetta Code that are difficult or
 impossible in other languages like Python or TCL?
 (or Lisp, JavaScript, Self/Smalltalk, Forth ...)

 Kind regards,

 Stephen
 On Wed, 29 Apr 2015 at 07:57, Jens Axel Søgaard jensa...@soegaard.net
 wrote:

 Great news!

 Worth a blog post to follow up on:

 http://blog.racket-lang.org/2013/03/200_25.html
 http://blog.racket-lang.org/2014/11/800.html

 /Jens Axel



 2015-04-29 1:38 GMT+02:00 Tim Brown t...@cityc.co.uk:

 Folks,

 I've just done a quick burst of cherry picking tasks on Rosetta
 Code (www.rosettacode.org). I took a quick look at:
 * http://rosettacode.org/wiki/Category:Tcl
 and
 *  http://rosettacode.org/wiki/Category:Racket

 And they both have the line:
 The following 845 pages are in this category, out of 845 total. 

 I *think* that means that both Tcl and Racket have 845 tasks impemented,
 but short of walking down a printout with a pen (and it's far to late to
 be doing that) -- I do believe that Tcl and Racket are now jointly the
 most popular programming languages on Rosetta Code.

 WELL DONE AND THANKS TO EVERYONE WHO HAS CONTRIBUTED (especially Racket)
 CODE ONTO ROSETTA CODE!

 And many, many thanks to the Racket team for producing a language which
 is now demonstrably as competent as any. (Although we all knew that
 before
 anyway, didn't we?)

 Tim

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




 --
 --
 Jens Axel Søgaard

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Rosetta Code: Level 1st (that's FIRST) with TCL

2015-05-04 Thread Jens Axel Søgaard
2015-04-29 14:07 GMT+02:00 Tim Brown tim.br...@cityc.co.uk:

 On 29/04/15 11:44, Stephen De Gabrielle wrote:

 Are there any tasks suitable for Rosetta Code that are difficult or
 impossible in other languages like Python or TCL? (or Lisp,
 JavaScript, Self/Smalltalk, Forth ...)


 Something specifically tuned to macros?

 Actually, (on a cursory search) there are no Anaphoric tasks; and
 Lisp is always so full of itself with aif et al.

 I think, though that this goes against the spirit of Rosetta Code's
 mission:

 From the very top of http://rosettacode.org/wiki/Rosetta_Code:

 ... The idea is to present solutions to the same task in as many
 different languages as possible, to demonstrate how languages are
 similar and different, and to aid a person with a grounding in one
 approach to a problem in learning another.



Well, they include gems like:

http://rosettacode.org/wiki/Break_OO_privacy

Quoting:

Show how to access private or protected members of a class in an
object-oriented language from outside an instance of the class, without
calling non-private or non-protected members of the class as a proxy. The
intent is to show how a debugger, serializer, or other meta-programming
tool might access information that is barred by normal access methods to
the object but can nevertheless be accessed from within the language by
some provided escape hatch or reflection mechanism. The intent is
specifically not to demonstrate heroic measures such as peeking and poking
raw memory.

Note that cheating on your type system is almost universally regarded as
unidiomatic at best, and poor programming practice at worst. Nonetheless,
if your language intentionally maintains a double-standard for OO privacy,
here's where you can show it off.

-- 
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] Time for draw-bitmap

2015-05-10 Thread Jens Axel Søgaard
2015-05-11 0:56 GMT+02:00 Matthew Flatt mfl...@cs.utah.edu:

 At Mon, 11 May 2015 00:30:05 +0200, Jens Axel Søgaard wrote:
  2015-05-11 0:07 GMT+02:00 Matthew Flatt mfl...@cs.utah.edu:
 
   If you're on OS X, try creating the bitmap with
  
(send canvas make-bitmap screen-width screen-height)
  
   instead of
  
(make-object bitmap% screen-width screen-height)
  
   Roughly, using the `make-bitmap` method creates a bitmap that's on the
   graphics card instead of main memory.
 
 
  Two thoughts:
- will make-screen-bitmap work too?

 No, only the `make-bitmap` method.

 See also
  http://docs.racket-lang.org/draw/overview.html#%28part._.Portability%29


Ok.


- If I insert images in the teaching languages,
  do they become screen-bitmaps automatically?

 No, I don't think so.

 It's possible that it would make sense for `freeze` to use
 `make-bitmap`-method bitmaps. The `pict-pre-render-pict` function is
 similar to `freeze`, except that it's for picts in Slideshow, and it
 does use the `make-bitmap` method of Slideshow's canvas. (As you might
 guess, Slideshow was the original motivation for the feature.) I'm not
 certain that using a `make-bitmap` method would make as much sense even
 for `freeze`, since those images are less tied to a specific
 destination.


Thanks.

-- 
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] Time for draw-bitmap

2015-05-10 Thread Jens Axel Søgaard
2015-05-11 2:24 GMT+02:00 Robby Findler ro...@eecs.northwestern.edu:

 But if you have a specific destination in mind you can make the bitmap
 first and then draw the 2htdp/image into it (or anything into it!)


When I use my own game-loop it is easy enough to use the make-bitmap method
of the canvas.

I did see a significant improvement in responsiveness, so I thought maybe
the same trick could be used in the implementation of big-bang. It's
tricky though since the user produces the bitmaps, not the big-bang loop
itself.

FWIW: On OS X the difference between the two methods is so large the game
went from unplayable to playable (due to a single call to draw-bitmap).
I saw times between 7-9 milliseconds for the call.

/Jens Axel

-- 
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] Time for draw-bitmap

2015-05-10 Thread Jens Axel Søgaard
Worked like a charm.

Thanks!

2015-05-11 0:07 GMT+02:00 Matthew Flatt mfl...@cs.utah.edu:

 If you're on OS X, try creating the bitmap with

  (send canvas make-bitmap screen-width screen-height)

 instead of

  (make-object bitmap% screen-width screen-height)

 Roughly, using the `make-bitmap` method creates a bitmap that's on the
 graphics card instead of main memory.

 At Sun, 10 May 2015 23:14:08 +0200, Jens Axel Søgaard wrote:
  Hi All,
 
  The attached files are a work-in-progress. Eventually it will become a
  remake of Cees Kramer's Snoopy for C64.
 
  Anyways, the game represents an unmoveable object as a block structure.
  Today I decided to stop rendering the blocks for every frame. Instead
  they are rendered once to a background image, and then simply
  replace (send dc clear) with (send dc draw-bitmap the-background 0 0)
  in the game loop.
 
  To my surprise the frame rate dropped. It seems draw-bitmap is more
  expensive than I thought.?  Or ... perhaps I am doing something
  that trips up draw-bitmap?
 
  Anyways, I have attached the game. To see the difference: Hold down
  the space bar.
 
  /Jens Axel

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Time for draw-bitmap

2015-05-10 Thread Jens Axel Søgaard
Hi All,

The attached files are a work-in-progress. Eventually it will become a
remake of Cees Kramer's Snoopy for C64.

Anyways, the game represents an unmoveable object as a block structure.
Today I decided to stop rendering the blocks for every frame. Instead
they are rendered once to a background image, and then simply
replace (send dc clear) with (send dc draw-bitmap the-background 0 0)
in the game loop.

To my surprise the frame rate dropped. It seems draw-bitmap is more
expensive than I thought.?  Or ... perhaps I am doing something
that trips up draw-bitmap?

Anyways, I have attached the game. To see the difference: Hold down
the space bar.

/Jens Axel

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


snoopy.rkt
Description: Binary data


struct-utils.rkt
Description: Binary data


Re: [racket-users] Time for draw-bitmap

2015-05-10 Thread Jens Axel Søgaard
2015-05-11 0:07 GMT+02:00 Matthew Flatt mfl...@cs.utah.edu:

 If you're on OS X, try creating the bitmap with

  (send canvas make-bitmap screen-width screen-height)

 instead of

  (make-object bitmap% screen-width screen-height)

 Roughly, using the `make-bitmap` method creates a bitmap that's on the
 graphics card instead of main memory.


Two thoughts:
  - will make-screen-bitmap work too?
  - If I insert images in the teaching languages,
do they become screen-bitmaps automatically?

/Jens Axel

-- 
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] Strange behaviour of the eq? operator in racket repl

2015-05-18 Thread Jens Axel Søgaard
2015-05-18 21:25 GMT+02:00 Michael Tiedtke michael.tied...@o2online.de:

 Il giorno 18/mag/2015, alle ore 20.50, Jos Koot ha scritto:

  I think Rackets's reference and guide are *very clear* about eq?, eqv?
 and
  equal?.

 Yes, right. It was the Racket Reference to tell me exactly that eqv? is an
 eq? that
 works for numbers and characters, too. I really had to look this up and
 found an
 simple and concise description.

 But the entries for for-each and map do not state anything about the
 execution order
 of the list processing.


Here is what the documentation say:

  Racket docs: Applies proc to the elements of the lsts from the first
elements to the last.
  R5RS: The dynamic order in which proc is applied to the elements of the
lists is unspecified.

I interpret the Racket docs to mean that the procedure are applied to the
elements in the list in the order they appear in the list.

In contrast R5RS (on purpose) state that the order is unspecified, which
means that an implementor of R5RS Scheme is free to choose the order which
fits his system best. Potentially the freedom to choose the order could
enable some optimizations.

-- 
Jens Axel Søgaard

-- 
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] literals within syntax-transfromer within syntax-transformer

2015-04-16 Thread Jens Axel Søgaard
The literals in the syntax-case expression needs to have the same context
as the identifiers used in the expressions where try is used.

#lang racket

(require (for-syntax racket))

(define-syntax (try stx)
  (define-syntax (stx-case stx)
(syntax-case stx ()
  ((_ stx-expr clause ...)
   (with-syntax ([+ (datum-syntax stx '+)]
 [- (datum-syntax stx '-)])
   #'(syntax-case stx-expr (+ -) clause ...)
  (stx-case stx
((_ +) #''plus)
((_ -) #''minus)
((_ x) #''x)))

(try +)
(try -)
(try a)


2015-04-16 16:35 GMT+02:00 Jos Koot jos.k...@gmail.com:

  Probably I am mixing literal identifiers from distinct expansion phases.
 Nevertheless, I don't understand the behaviour of the program below.
 Explanation would be very welcome.
 I have looked into the expanded code with the macro stepper,
 but I could not find any code looking for the literals.

 #lang racket

 (require (for-syntax racket))

 (define-syntax (try stx)
  (define-syntax (stx-case stx)
   (syntax-case stx ()
((_ stx-expr clause ...) #'(syntax-case stx-expr (+ -) clause ...
  (stx-case stx
   ((_ +) #''plus)
   ((_ -) #''minus)
   ((_ x) #''x)))

 (try +) ; - plus; as expected
 (try -) ; - plus; expected -
 (try a) ; - plus; expected a

 I did this in the definitions window of DrRacket, version 6.1.1 [3m].
 Language: racket [custom]; memory limit: 2000 MB.

  Thanks, Jos Koot

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




-- 
-- 
Jens Axel Søgaard

-- 
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] carmack s-expression tweet

2015-04-15 Thread Jens Axel Søgaard
FWIW the binary-class package by Roman Klochkov looks pretty nice:

http://pkg-build.racket-lang.org/doc/binary-class/index.html

/Jens Axel


2015-04-15 11:08 GMT+02:00 Adriaan Leijnse adriaan.leij...@gmail.com:

 On Saturday, March 28, 2015 at 12:15:39 AM UTC+1, Alexis King wrote:
  It might be interesting to create a binary s-expression format for more
 efficient reading/writing, a la BSON’s relationship to JSON. Perhaps even
 with some sort of optional compression. Racket’s reader is fairly
 complicated, though, so it might need to restrict itself to a useful subset?

 I think the Clojure community has built exactly what you're thinking of:
 https://github.com/Datomic/fressian/wiki

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




-- 
-- 
Jens Axel Søgaard

-- 
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] advice for writing desktop app

2015-04-04 Thread Jens Axel Søgaard
Tree?

Do you mean this?

http://docs.racket-lang.org/mrlib/Hierarchical_List_Control.html?q=button%25

/Jens Axel


2015-04-04 10:30 GMT+02:00 Gour g...@atmarama.net:

 Alexander D. Knauth alexan...@knauth.org writes:

 Here it is, although some of the things I did like creating objects on a
 dummy panel and then reparenting them seem like they could be bad ideas.
 https://github.com/AlexKnauth/racket-gui-table

 Thank you. I did star it.

 What about trees? You don't have need for it?


 Sincerely,
 Gour

 --
 One is understood to be in full knowledge whose every endeavor
 is devoid of desire for sense gratification.

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



-- 
--
Jens Axel Søgaard

-- 
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] Color Arithmetic

2015-06-04 Thread Jens Axel Søgaard
2015-06-04 11:38 GMT+02:00 Michael Tiedtke michael.tied...@o2online.de:


 Before I go ahead and just do it I wanted to ask:

 1) Does such a thing exist somewhere for Scheme or Racket (I couldn't find
 anything)
  The only example I found was:
 https://www.wolframalpha.com/examples/ColorArithmetic.html


FWIW here is a few color related functions/utilities:

Docs:
http://soegaard.github.io/docs/metapict/metapict.html#%28part._ref-colors%29
Code: https://github.com/soegaard/metapict/blob/master/metapict/color.rkt
Also:  https://github.com/mbutterick/css-tools/blob/master/colors.rkt


/Jens Axel

-- 
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] racket virtual machine

2015-06-03 Thread Jens Axel Søgaard
Depends. If you count all the primitives - then one-month won't be enough.

The actual operations of the virtual machine are certainly doable in a
reasonable amount of time.

A Racket VM written in Racket:

https://github.com/soegaard/meta/blob/master/runtime/racket-eval.rkt

(submodules not supported yet, but it is a relatively small change).

/Jens Axel


2015-06-04 0:59 GMT+02:00 Neil Van Dyke n...@neilvandyke.org:

 How hard is it to implement the Racket virtual machine (no JIT) for a
 single target architecture one knows?

 Say, is this a one-weekend task, or a one-month task?

 Neil V.

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




-- 
-- 
Jens Axel Søgaard

-- 
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] racket virtual machine

2015-06-05 Thread Jens Axel Søgaard
2015-06-05 6:37 GMT+02:00 Neil Van Dyke n...@neilvandyke.org:


 2. Forget about `eval`, require apps to be compilable on development host
 (but not necessarily runnable there), implement compiler from `.zo` to JS
 (managing TCO, etc.), implement small Racket runtime library in JS,
 implement browser facilities and/or GUI libraries in JS.  Later think about
 `eval`.[*]


This approach seems to be what Whalesong does. I agree that `eval` is
unimportant for most programs - and when a Racket version of the new macro
expander is available it ought
to be reasonably easy to implement `eval`.


 [*] I've only done a very brief peek at sample `zo-parse` and `decompile`
 output, so I don't know how tricky it can get, but the little I saw looked
 like a static translation to JS wouldn't be too difficult.  I don't know
 how necessary `eval` is if you have bytecode, nor how much of the
 primitives would have to be implemented manually rather than translated
 from `.zo`.


There are a few complications. It is hard to use the native JavaScript
stack to
represent the Racket stack. Some byte codes like with-cont-mark manipulate
the stack
in ways JavaScript doesn't support. Some primitives (call/cc and friends)
are
also problems unless an explicit representation of the Racket stack is used.

Whalesong compiles zo-bytecode into JavaScript that manipulate an explicit
data structure representing the Racket stack.

The alternative approach is to compile fully expanded Racket into
JavaScript.
The trio of TCO, contination marks and continuations will most likely turn
out to be the trickiest to get right.

Even with an explicit control stack for Racket care is needed to avoid
hitting the stack ceiling in JavaScript (why was `goto` left out in the
cold?)

Finally - a small runtime library is probably unrealistic. Racket has
a huge number of primitives.


Relevant paper on continuation marks and continuations from exceptions:

http://cs.brown.edu/~sk/Publications/Papers/Published/pcmkf-cont-from-gen-stack-insp/paper.pdf


Note:

The paper Implementing Continuation Marks in JavaScript shows how to add
continuation marks to an existing JavaScript engine (Rhino), but
unfortunately that won't help in a general context.

Implementing Continuation Marks in JavaScript
John Clemens, Ayswarya Sundaram, and, David Herman
http://www.ccs.neu.edu/home/dherman/research/papers/scheme08-stack-marks.pdf

-- 
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] Closing big-bang windows

2015-06-23 Thread Jens Axel Søgaard
John Carmack:

 My son's game has a level editor as well as a game loop, and we switch
 between them.  However, each new big-bang call creates a new window,
 leaving the previous ones inert on the screen.  How can we close the
 windows?



Matthias Felleisen:

 But people wanted it to stay
 open so that they could see the final score of their games etc.

 I guess I could add a close-on-stop clauses for programmers
 such as your son but it sounds almost like he's ready to move
 on to racket proper, as in use the Windowing API directly.


If I understand correctly, a manual

   (close-all-big-bang-windows)

callable from the REPL would be enough in this case?

/Jens Axel

-- 
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: Fast way to map over a list many times, changing ONE element each time?

2015-06-19 Thread Jens Axel Søgaard
Hi Luke,

What are the result on lists of length 1000?

Also can you post the benchmarking code?

/Jens Axel



2015-06-19 22:33 GMT+02:00 Luke Miles rashreportl...@gmail.com:

 I timed all these with `sqr` on a list of 1 `(random)`.

 Luke's (my) first one:
 cpu time: 4706 real time: 4699 gc time: 3673

 Luke's second one:
 cpu time: 5401 real time: 5393 gc time: 4136

 Jon's first one:
 cpu time: 9734 real time: 9728 gc time: 8007

 Jon's second one (tested on a vector of course):
 cpu time: 1198 real time: 1195 gc time: 883

 Jens' first one:
 cpu time: 5622 real time: 5618 gc time: 4800

 Jens' second one:
 cpu time: 4393 real time: 4391 gc time: 3935


 I thought Jens' second one would be faster. The vector's results are
 promising.

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Fast way to map over a list many times, changing ONE element each time?

2015-06-19 Thread Jens Axel Søgaard
A more efficient version using append-reverse from srfi/1.

#lang racket
(require (only-in srfi/1 append-reverse))

(define (list-splits xs)
  (define (loop ys zs)  ; xs = (append (reverse ys) yz)
(match zs
  ['()  '()]
  [(cons z zs*) (cons (list ys zs)
  (loop (cons z ys) zs*))]))
  (loop '() xs))


(define (map-once f xs)
  (for/list ([ys+zs (list-splits xs)])
(match ys+zs
  [(list ys '()) '()]
  [(list ys (cons z zs)) (append-reverse ys (cons (f z) zs))])))

(list-splits  '(1 2 3))
(map-once sqr '(1 2 3))


2015-06-19 22:07 GMT+02:00 Jens Axel Søgaard jensa...@soegaard.net:

 #lang racket
 (define (list-splits xs)
   (define (loop ys zs)  ; xs = (append (reverse ys) yz)
 (match zs
   ['()  '()]
   [(cons z zs*) (cons (list ys zs)
   (loop (cons z ys) zs*))]))
   (loop '() xs))


 (define (map-once f xs)
   (for/list ([ys+zs (list-splits xs)])
 (match ys+zs
   [(list ys '()) '()]
   [(list ys (cons z zs)) (append (reverse ys) (cons (f z) zs))])))

 (list-splits  '(1 2 3))
 (map-once sqr '(1 2 3))


 2015-06-19 22:05 GMT+02:00 Jon Zeppieri zeppi...@gmail.com:

 It's unlikely that an implementation using continuations would be
 faster than one that does not.

 An idiomatic solution might look like:

 (define (map-once fn xs)
   (for/list ([i (in-range (length xs))])
 (for/list ([(x j) (in-indexed (in-list xs))])
   (cond [(= i j) (fn x)]
 [else x]


 But it's not terribly fast.
 If you're willing to use vectors instead of lists, then maybe:

 (define (map-once fn xs)
   (build-vector (vector-length xs)
 (λ (i)
   (define v (vector-copy xs))
   (vector-set! v i (fn (vector-ref v i)))
   v)))


 On Fri, Jun 19, 2015 at 3:24 PM, Luke Miles rashreportl...@gmail.com
 wrote:
  Say I have a list ls and I want to produce a list of
  lists where the i'th list has the i'th element of ls tripled,
  but all other elements are the same.
 
  e.g. '(3 5 7) = '((9 5 7) (3 15 7) (3 5 21))
 
  What is a fast way to do this?
 
 
  I could do a loop with appending.
  (define (map-once f ls)
(let M ([sooner null] [later ls])
  (if (null? later) null
(cons (append sooner (list (f (car later))) (cdr later))
  (M (append sooner (list (car later))) (cdr later))
 
  - (map-once sqr '(4 5 6))
  '((16 5 6) (4 25 6) (4 5 36))
 
  Unfortunately, this is very slow  messy.
  I have to do 2 big appends for every element is the return list.
 
 
  Here is a cleaner-looking, but still slow way:
  (define (list-set ls i new-val)
(let-values ([(sooner later) (split-at ls i)])
  (append sooner (list new-val) (cdr later
 
  (define (map-once f ls)
(for/list ([i (in-naturals)]
   [elm (in-list ls)])
  (list-set ls i (f elm
 
 
  I'm thinking a good implementation might use continuations somehow?
 
  Maybe of vector-set (without the exclamation point) existed, I could
 use it?
 
  --
  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.




 --
 --
 Jens Axel Søgaard




-- 
-- 
Jens Axel Søgaard

-- 
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] Fast way to map over a list many times, changing ONE element each time?

2015-06-19 Thread Jens Axel Søgaard
#lang racket
(define (list-splits xs)
  (define (loop ys zs)  ; xs = (append (reverse ys) yz)
(match zs
  ['()  '()]
  [(cons z zs*) (cons (list ys zs)
  (loop (cons z ys) zs*))]))
  (loop '() xs))


(define (map-once f xs)
  (for/list ([ys+zs (list-splits xs)])
(match ys+zs
  [(list ys '()) '()]
  [(list ys (cons z zs)) (append (reverse ys) (cons (f z) zs))])))

(list-splits  '(1 2 3))
(map-once sqr '(1 2 3))


2015-06-19 22:05 GMT+02:00 Jon Zeppieri zeppi...@gmail.com:

 It's unlikely that an implementation using continuations would be
 faster than one that does not.

 An idiomatic solution might look like:

 (define (map-once fn xs)
   (for/list ([i (in-range (length xs))])
 (for/list ([(x j) (in-indexed (in-list xs))])
   (cond [(= i j) (fn x)]
 [else x]


 But it's not terribly fast.
 If you're willing to use vectors instead of lists, then maybe:

 (define (map-once fn xs)
   (build-vector (vector-length xs)
 (λ (i)
   (define v (vector-copy xs))
   (vector-set! v i (fn (vector-ref v i)))
   v)))


 On Fri, Jun 19, 2015 at 3:24 PM, Luke Miles rashreportl...@gmail.com
 wrote:
  Say I have a list ls and I want to produce a list of
  lists where the i'th list has the i'th element of ls tripled,
  but all other elements are the same.
 
  e.g. '(3 5 7) = '((9 5 7) (3 15 7) (3 5 21))
 
  What is a fast way to do this?
 
 
  I could do a loop with appending.
  (define (map-once f ls)
(let M ([sooner null] [later ls])
  (if (null? later) null
(cons (append sooner (list (f (car later))) (cdr later))
  (M (append sooner (list (car later))) (cdr later))
 
  - (map-once sqr '(4 5 6))
  '((16 5 6) (4 25 6) (4 5 36))
 
  Unfortunately, this is very slow  messy.
  I have to do 2 big appends for every element is the return list.
 
 
  Here is a cleaner-looking, but still slow way:
  (define (list-set ls i new-val)
(let-values ([(sooner later) (split-at ls i)])
  (append sooner (list new-val) (cdr later
 
  (define (map-once f ls)
(for/list ([i (in-naturals)]
   [elm (in-list ls)])
  (list-set ls i (f elm
 
 
  I'm thinking a good implementation might use continuations somehow?
 
  Maybe of vector-set (without the exclamation point) existed, I could use
 it?
 
  --
  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.




-- 
-- 
Jens Axel Søgaard

-- 
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 Simple Bugs and Fixing Them

2015-06-20 Thread Jens Axel Søgaard
2015-06-20 3:12 GMT+02:00 Vincent St-Amour stamo...@ccs.neu.edu:

 For changes like typoes, Github has a pencil button at the top of its
 source view that simplifies the pull-request process.


 https://help.github.com/articles/editing-files-in-another-user-s-repository/


That's the simplest way of fixing typos.

Is there somewhere we can advertise this?

/Jens Axel

-- 
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: Fast way to map over a list many times, changing ONE element each time?

2015-06-22 Thread Jens Axel Søgaard
Hi Luke,

With 5000 numbers I got the numbers below with a slightly modified
benchmark.
If one method generates garbage and triggers a garbage collection while
running the following method, then the numbers will be unfair. To avoid
this I call collect-garbage before calling time.

map-once method number 1:
cpu time: 2832 real time: 3406 gc time: 1970
cpu time: 1895 real time: 1973 gc time: 1472
cpu time: 1941 real time: 2070 gc time: 1514


map-once method number 2:
cpu time: 2212 real time: 2288 gc time: 1687
cpu time: 2320 real time: 2395 gc time: 1766
cpu time: 2344 real time: 2451 gc time: 1815


map-once method number 3:
cpu time: 12547 real time: 13146 gc time: 11738
cpu time: 10687 real time: 10824 gc time: 9930
cpu time: 10615 real time: 10786 gc time: 9860


map-once method number 4:
cpu time: 1718 real time: 1795 gc time: 1379
cpu time: 1796 real time: 1827 gc time: 1403
cpu time: 1751 real time: 1816 gc time: 1380


map-once method number 5:
cpu time: 1311 real time: 1381 gc time: 1081
cpu time: 1346 real time: 1401 gc time: 1119
cpu time: 1375 real time: 1491 gc time: 1129


vector method:
cpu time: 1063 real time: 1154 gc time: 365
cpu time: 942 real time: 1024 gc time: 366
cpu time: 921 real time: 1002 gc time: 391


#lang racket
; testing for post on racket mailing list
; https://groups.google.com/forum/#!topic/racket-users/7lkOjjpVa6A

;; Luke
(define (map-once/1 f ls)
  (let M ([sooner null] [later ls])
(if (null? later) null
(cons (append sooner (list (f (car later))) (cdr later))
  (M (append sooner (list (car later))) (cdr later))


(define (list-set ls i new-val)
  (let-values ([(sooner later) (split-at ls i)])
(append sooner (list new-val) (cdr later

(define (map-once/2 f ls)
  (for/list ([i (in-naturals)]
 [elm (in-list ls)])
(list-set ls i (f elm

;; Jon
(define (map-once/3 fn xs)
  (for/list ([i (in-range (length xs))])
(for/list ([(x j) (in-indexed (in-list xs))])
  (cond [(= i j) (fn x)]
[else x]


(define (map-once/v fn xs)
  (build-vector (vector-length xs)
(λ (i)
  (define v (vector-copy xs))
  (vector-set! v i (fn (vector-ref v i)))
  v)))


;; Jens
(define (list-splits xs)
  (define (loop ys zs)  ; xs = (append (reverse ys) yz)
(match zs
  ['()  '()]
  [(cons z zs*) (cons (list ys zs)
  (loop (cons z ys) zs*))]))
  (loop '() xs))

(define (map-once/4 f xs)
  (for/list ([ys+zs (list-splits xs)])
(match ys+zs
  [(list ys '()) '()]
  [(list ys (cons z zs)) (append (reverse ys) (cons (f z) zs))])))


(require (only-in srfi/1 append-reverse))

(define (map-once/5 f xs)
  (for/list ([ys+zs (list-splits xs)])
(match ys+zs
  [(list ys '()) '()]
  [(list ys (cons z zs)) (append-reverse ys (cons (f z) zs))])))


;;; actual testing

(define num-test-cases 5000)
(define num-runs-per-f 3)

(define ls (for/list ([__ (in-range num-test-cases)]) (random)))

(define normal-map-onces
  (list map-once/1 map-once/2 map-once/3 map-once/4 map-once/5))

(for ([map-once (in-list normal-map-onces)]
  [i (in-naturals)])
  (printf \n\nmap-once method number ~a:\n (+ i 1))
  (for ([__ (in-range num-runs-per-f)])
(collect-garbage)
(collect-garbage)
(collect-garbage)
(time (void (map-once sqr ls)

(define v (for/vector ([__ (in-range num-test-cases)]) (random)))
(printf \n\nvector method:\n)
(for ([__ (in-range num-runs-per-f)])
  (collect-garbage)
  (collect-garbage)
  (collect-garbage)
  (time (void (map-once/v sqr v


2015-06-19 23:08 GMT+02:00 Luke Miles rashreportl...@gmail.com:

 My 1000 numbers were so small that they weren't reliable.

 Change the `num-runs-per-f` and experiment yourself, if you'd like.
 The code is attached.

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Get list of all predefined identifiers for use in vim syntax highlighting

2015-06-01 Thread Jens Axel Søgaard
Hi Luke,

This script generates a large list of keywords. It was used to generate the
keywords for the Github highlighter.

https://github.com/soegaard/racket-highlight-for-github/blob/master/generate-keywords.rkt

/Jens Axel


2015-06-01 17:07 GMT+02:00 Luke Miles rashreportl...@gmail.com:

 For those who like to write their racket code in vim, the plugin
 https://github.com/wlangstroth/vim-racket is pretty essential.

 Unfortunately, it is outdated and many of the new predefined identifiers
 (e.g. set-add!) are not highlighted.

 I added a few of these in my personal settings, but it would be nice to
 have a text file with every special form and every function listed.

 Is this list floating around somewhere? If not, is there an easy way to
 generate it?

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Room for descriptions

2015-07-03 Thread Jens Axel Søgaard
Thanks!

No wonder I couldn't find it in the preferences.

/Jens Axel

2015-07-03 18:59 GMT+02:00 Robby Findler ro...@eecs.northwestern.edu:

 That sounds like it would be a very nice change.

 The option you want is in the view menu.

 Robby


 On Friday, July 3, 2015, Jens Axel Søgaard jensa...@soegaard.net wrote:

 Hi All,

 During the installation of DrRacket on a new laptop I realized
 that the preferences dialog could need some kind of info
 on each available option.

 Consider this:

  http://i.imgur.com/IzsJrI8.png

 There is lots of room to the right for a description.

  Map delete to backspace
  Treat alt key as meta
  What are the implications?
  Why would anyone do that?

 Maximum character width guide
 Huh?
 (Should this be on by default? btw)

Search using anchors

 In the General tab there is a:
  Enable automatic parentheses
 In the Racket tab there is a:
 Automatically adjust opening square brackets

 If you have tried them before, you might remember what they do,
 but if not ...


 Anyways, I was actually looking for the option that moves the tool
 buttons to left of the screen rather than on top. Where is it?

 /Jens Axel

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Room for descriptions

2015-07-03 Thread Jens Axel Søgaard
Hi All,

During the installation of DrRacket on a new laptop I realized
that the preferences dialog could need some kind of info
on each available option.

Consider this:

 http://i.imgur.com/IzsJrI8.png

There is lots of room to the right for a description.

 Map delete to backspace
 Treat alt key as meta
 What are the implications?
 Why would anyone do that?

Maximum character width guide
Huh?
(Should this be on by default? btw)

   Search using anchors

In the General tab there is a:
 Enable automatic parentheses
In the Racket tab there is a:
Automatically adjust opening square brackets

If you have tried them before, you might remember what they do,
but if not ...


Anyways, I was actually looking for the option that moves the tool
buttons to left of the screen rather than on top. Where is it?

/Jens Axel

-- 
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] on module: identifier already imported from a different source

2015-06-30 Thread Jens Axel Søgaard
Hi Daniel,

The problems is that math/number-threory and racket/list
both export an function named permutations.

You are right that rename-in or prefix-in could be used to
fix the problem in full Racket. In order to handle the
situation in ISL+ I suggest to make an extra file:

File: no-conflicts.rkt
#lang racket
(provide (all-from-out math/number-theory)
 (all-from-out racket/list))
(require math/number-theory)
   (require (except-in racket/list permutations))

And then in the ISL+ file write (require no-conflicts.rkt).

/Jens Axel




2015-06-30 14:23 GMT+02:00 Daniel Bastos dbas...@toledo.com:

 I'm getting module: identifier already imported from a different
 source when I require these two modules.

 (require math/number-theory)
 (require racket/list)

 I want factorize from math/number-theory and remove-duplicates from
 racket/list.

 I've seen old messages about this error, but they seemed involved with
 the full-fledged Racket, while I'm using ISL+ in DrRacket. I decided
 to try some things out of HtDP and ended up getting into this trouble.

 I don't want the full-fledged Racket because I like to use
 check-expect in DrRacket and I seem to get along better with the
 student languages error messages.

 Solutions such as (require (rename ... ) don't work for me because I'm
 speaking ISL+ where my options seem to me these below. (ASL doesn't
 seem to expand on it.)

   library-require = (require string)
  | (require (lib string string ...))
  | (require (planet string package))

 Perhaps you could suggest me to leave the student languages sometimes
 when playing with Racket by showing me how I could get some equivalent
 thing to check-expect.

 At some point I should move to full-fledged Racket. I suppose after
 HtDP I should read another book. Perhaps Realm of Racket?

 Thank you.

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Emacs Lisp as a Racket Language?

2015-07-02 Thread Jens Axel Søgaard
https://github.com/tonyg/rmacs

Also: Read this free book:
http://www.finseth.com/craft/



2015-07-02 23:00 GMT+02:00 Greg Davidson greg.david...@gmail.com:

 Thanks Matthias ... there's nothing on Tony's projects pages so I've sent
 him a message.  _Greg

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Simple Interdependent Units?

2015-05-25 Thread Jens Axel Søgaard
Hi Michael,

It would be interesting to hear about the situation that led to a cyclic
dependency.

The few cases where I have had a problem I managed to solve it by moving
all structure definitions into a separate module structs.rkt and then
requiring
that module everywhere else.

/Jens Axel






2015-05-25 11:52 GMT+02:00 Michael Tiedtke michael.tied...@o2online.de:

 As I had to find out Racket's module system doesn't support cyclic
 dependencies. In that case I should use units. But as far as I have
 understood the concept of full fledged units I must either write a lot of
 redundant code like *signature auto^*, *implementation auto@,* *import
 auto^*, *require auto.rkt,* *export auto^* etc
 OR I could create a lot of files following a certain naming conventions
 when using whole module units. Both approaches are more hassle than
 managing the respective files of my framework with copypaste and via
 *include.*

 *Isn't there any simple way to declare cyclic dependencies?*

 Can I put the signature and the implementation into one file?

 How do I require or import such an interdependent unit framework? Do I
 have to use invoke-unit or require or ...?

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




-- 
-- 
Jens Axel Søgaard

-- 
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 fill a shape with a texture using 2htdp/image or similar?

2015-05-22 Thread Jens Axel Søgaard
Maybe there are other useful pict/brush modifiers of interest?

https://github.com/soegaard/metapict/blob/master/metapict/pict.rkt#L149

/Jens Axel


2015-05-21 18:41 GMT+02:00 Robby Findler ro...@eecs.northwestern.edu:

 Oh, nice! We should add brushstipple to pict itself.

 Robby

 On Thu, May 21, 2015 at 11:28 AM, Jens Axel Søgaard
 jensa...@soegaard.net wrote:
  Here is an example from MetaPict:
 
 
 http://soegaard.github.io/docs/metapict/metapict.html#%28def._%28%28lib._metapict%2Fpict..rkt%29._brushstipple%29%29
 
  The same effect can be achieved by setting the brush to a stipple
  and then filling a path.
 
  /Jens Axel
 
 
  2015-05-20 17:03 GMT+02:00 Robby Findler ro...@eecs.northwestern.edu:
 
  2htdp/image doesn't support that now, but the color argument of
  various functions there could be generalized to support a new brush
  struct (in the way that pen structs work for outline images) that had
  a bitmap field to do what you want. The internal helper function
  mode-color-brush would have to change to support that, which would be
  pretty straightforward I expect (it creates a brush% object). And then
  there's the work of updating the documentation and adding new examples
  and test cases.
 
  The relevant files are mrlib/image-core and various files in the 2htdp
  collection. Patches welcome. :)
 
  Robby
 
 
  On Tue, May 19, 2015 at 6:36 PM, Daniel Prager
  daniel.a.pra...@gmail.com wrote:
   2htdp/image makes it easy to draw all sorts of solid shapes
 (triangles,
   squares, stars, etc.) and fill them with a solid color.
  
   But say I want to fill with a texture (say from a bitmap loaded from a
   file). I could brute-force it by creating a separate stencil image,
   converting both to pixels and converting back, but that seems
 laborious,
   or
   presumably switch to GL.
  
   Any other ideas?
  
   Thanks
  
   Dan
  
   --
   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.
 
 
 
 
  --
  --
  Jens Axel Søgaard
 

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




-- 
-- 
Jens Axel Søgaard

-- 
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] DrRacket rendering issues OS X

2015-08-18 Thread Jens Axel Søgaard
Apropos rendering issues on OS X. With a retina display the little dropdown
triangles in DrRacket (the one next to the delta - menu that shows
definitions) have slightly jarred edges.

/Jens Axel



2015-08-18 22:09 GMT+02:00 Andrew Kent sgt...@gmail.com:

 Just an update/bump: I'm still seeing this issue in DrRacket on the latest
 git checkouts. I went ahead replicated the issue on a friend's mac w/ OS X
 Yosemite w/ the 6.2 release as well (just to make sure I wasn't crazy or
 causing the issue on my machine).[image: Screen Shot 2015-08-18 at
 4.07.23 PM.png]


 On Wed, Jun 17, 2015 at 7:13 PM Matthew Flatt mfl...@cs.utah.edu wrote:

 At Wed, 17 Jun 2015 12:35:36 -0700 (PDT), Andrew Kent wrote:
  On Wednesday, June 17, 2015 at 3:10:51 PM UTC-4, Alex Knauth wrote:
   One data point:
   I’m using DrRacket version 6.2.0.4--2015-06-08 with OS X Version
 10.9.5, and
  if I remember correctly it was a Racket plus Tests 64-bit installation.
   I tried those steps, and it worked fine, with no weird black areas,
 though I
  do remember occasionally getting similar small black areas in the past,
  covering just the tab bar or something like that, and when I moved my
 mouse
  over it it fixed itself? I’m not sure if I remember that correctly, and
 I’m not
  sure if that could be related to what you got, because that wasn’t with
 full
  screen or the mission control screen, and I could not produce that
 consistently.
  
  
   On Jun 17, 2015, at 12:25 PM, Andrew Kent andm...@indiana.edu
 wrote:
  
  
   Good day all!
  
  
   First, I just wanted to say DrRacket is *amazing* and thank all who
 have
  helped it become what it is today! I'm currently using it to work on
 Typed
  Racket and it is a godsend.
  
  
   Right now, unfortunately, I am having some problems w/ DrRacket
 rendering in
  OS X -- I am getting large black areas appearing in full screen mode in
  DrRacket. They seem pretty serious/severe, and I was curious if anyone
 else has
  seen this behavior?
  
  
  
   PDF w/ screenshots  some attempt to describe problem(s):
  
 https://drive.google.com/file/d/0B-HcU1nZPrwJWXFNbEdOV0doeUE/view?usp=sharing
  
  
   Steps that seem to recreate issue:
   1) Open DrRacket
   2) Make it full screen by clicking green button at top left of
 DrRacket
   3) Open OS X ‘Mission Control’ (cmd+up or 3-finger-swipe up on
 touchpad) 4)
  Close OS X ‘Mission Control’ (cmd+down or 3-finger-swipe downon
   touchpad) nd
   5) Repeat 3-4 a couple times (after the 2 time it seemed to
 consistently
   happen on my machine)
  
  
   - This worked whether or not I was plugged into the external monitor
   - the snapshots reproduced the issue on were the Racket plus Tests |
 Mac OS X
  | 32-bit Intel distribution for version 6.2.0.4 (20150609-bf12a2b) 
 version
  6.2.0.4 (20150617-97827ac)
   - I’m running the latest OS X Yosemite (Version 10.10.3 (14D136)) on
 a early
  2013 13” MacBook Air
  
  
  
  
   Best,
   Andrew
 
  Additional note/update:
  When I was writing up the bug description those steps _were_ working
  consistently for me. Now, however, they do not... but somewhat
 erratically
  jumping workspaces left to right (I have Powerpoint full screened at
 the moment
  as well) mixed w/ some Mission Control access can cause it.
 
  So, I can't figure out how to do it 100% consistently, but it is
 definitely a
  reoccurring issue and sometimes I end up just having to close DrRacket
 to make
  it go away.

 I haven't been able to replicate the problem, but I'm also using
 Mavericks. This problem could easily be specific to Yosemite, and I'll
 check when I get back to my Yosemite machine in a couple of weeks.

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




-- 
-- 
Jens Axel Søgaard

-- 
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] My son's game in Racket

2015-08-24 Thread Jens Axel Søgaard
2015-08-24 18:27 GMT+02:00 John Carmack jo...@oculus.com:

 We “released” my 10 year old son’s game that was done in Racket:
 www.1k3c.com


Tell him, he has done a great job.

It has the right game feel. I liked both how the levels progressed slowly
in difficulty
and that there were so many of them.

/Jens Axel

-- 
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] `divides?` from math/number-theory slow?

2015-08-24 Thread Jens Axel Søgaard
I hope someone has solution. It looks very odd to me.

The function divides? is defined in

https://raw.githubusercontent.com/racket/math/master/math-lib/math/private/number-theory/divisibility.rkt

#lang typed/racket/base

(provide divides? coprime? pairwise-coprime? bezout)

;;;
;;; DIVISIBILITY
;;;

(: divides? : Integer Integer - Boolean)
; a divides b = exists unique k s.t. a*k=b
(define (divides? a b)
  (cond [(zero? a)  #f]
[else  (= (remainder b a) 0)]))




2015-08-24 12:41 GMT+02:00 Rickard Andersson rickard.m.anders...@gmail.com
:

 Hi,

 I noticed that the `divides?` function from math/number-theory seems to be
 a huge bottleneck for whatever reason.

 This seems strange to me, but I figured I'd write to the list to see if
 maybe there are trade-offs made that make sense mostly for big integers or
 something.

 Example with (time):

 #lang racket/base

 (require (only-in math/number-theory divides?))

 (define (divisible-by? x d)
   (= (modulo x d)
  0))

 (module+ main
   (time
 (for/sum ([x (in-range 3 5)])
   (if (3 . divides? . x)
 x
 0))) ; cpu time: 96257 real time: 96166 gc time: 128
   (time
 (for/sum ([x (in-range 3 5)])
   (if (x . divisible-by? . 3)
 x
 0))) ; cpu time: 7277 real time: 7266 gc time: 0
   )

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Sending Closures to Places

2015-08-03 Thread Jens Axel Søgaard
2015-08-02 19:12 GMT+02:00 Konstantin Weitz konstantin.we...@gmail.com:

 I'm trying to write a distributed racket program using [places][0]. From
 my current understanding, this means that I have to send data to each place
 over a channel using the `place-channel-put` function, which can send any
 value accepted by `place-message-allowed?`.

 I would like to send closures over a channel, unfortunately, closures are
 not accepted by `place-message-allowed?`. Is there any way to serialize a
 closure into a value accepted by a channel, and then deserialize it on the
 other side of the channel?


How many lambda expressions are we talking about?
If the number is limited you can defined custom closures.

Whether or not the following is practical I will leave up to you
to decide :-)


Consider this program.

(define x 3)
(define f (lambda (y) (+ x y)))
(f 4)

Annotate the free variables of the lambda-expression.

(define x 3)
(define f (lambda (y) (+ x y)))  ; x is free
(f 4)

Define an explicit closure struct and a helper to access free variables.

(struct closure (code free) #:prefab)

The code field will refer to a closed (no free variables) version of f and
free is a vector of the values of the free variables at the
time the closure was created.

The idea is that we want to replace (lambda (y) (+ x y)) with (closure
f_closed (vector x)).

A little helper to access the free variables:

(define (free-ref cl i)
  (vector-ref (closure-free cl) i))

Now define a closed (no free variables) version of f:

(define f_closed
  (lambda (cl y)
(let ((x (free-ref cl 0)))
  (+ x y

We can now rewrite the lambda expression into a closure allocation.

The full program is now:

(struct closure (code free) #:prefab)
(define (free-ref cl i)  (vector-ref (closure-free cl) i))

(define f_closed
  (lambda (cl y)
(let ((x (free-ref cl 0)))
  (+ x y

(define x 3)
(define f (closure f_closed (vector x)))
(f 4)

Note that the structure is a prefab structure in order to be a legal
message.

At this point there is a complication:

* f_closed is not an allowed message
* (f 4) fails since the closure structure is not applicable

The first point is solved by sending the name of f_closed as a symbol.
One could use eval to change it back to a function, but a hash table will
do:

(define closed-functions-ht
  (make-hasheq (list (cons 'f_closed f_closed

(define (get-closed-function name)
  (hash-ref closed-functions-ht name
(λ _ (error 'app no closed function of that name ~a
name

The other can unfortunately not be solved by turning the structure
into an applicable struct, since prefab structures can't have properties.
Therefore we need to introduce a construct app that knows how to invoke
closures.

(define-syntax-rule (app cl arg ...)
  ((get-closed-function (closure-code cl)) cl arg ...))

The entire program is now:

#lang racket
(struct closure (code free) #:prefab)
(define (free-ref cl i)  (vector-ref (closure-free cl) i))

(define f_closed
  (lambda (cl y)
(let ((x (free-ref cl 0)))
  (+ x y

(define closed-functions-ht
  (make-hasheq (list (cons 'f_closed f_closed

(define (get-closed-function name)
  (hash-ref closed-functions-ht name
(λ _ (error 'app no closed function of that name ~a
name

(define-syntax-rule (app cl arg ...)
  ((get-closed-function (closure-code cl)) cl arg ...))

(define x 3)
(define f (closure 'f_closed (vector x)))
(app f 4)

The value of f is:

 f
'#s(closure f_closed #(3))

and that value is an allowed message.

The standard higher operations such as map and apply do not know about the
special calling convention of f, so (map f '(1 2 3)) will not work.
It is no big deal though, since wrapping f in a lambda works:

 (map (λ (x) (app f x))
   '(1 2 3))
'(4 5 6)

To make this solution practical one could introduce a macro Lambda
that turns (Lambda (x) (y) (+ x y)) into (closure 'closed1 (vector x)))
and at the same time lifts

(define closed1
  (lambda (cl y)
(let ((x (free-ref cl 0)))
  (+ x y

to the top of the program.

An ambitious solution would also use free-vars from syntax/free-vars
to determine the free variables automatically.

/Jens Axel

-- 
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] Sending Closures to Places

2015-08-03 Thread Jens Axel Søgaard
Note that the web-server has support for serializable closures:

http://docs.racket-lang.org/web-server-internal/closure.html

I think they are the practical choice.

/Jens Axel


2015-08-03 12:29 GMT+02:00 Jens Axel Søgaard jensa...@soegaard.net:

 2015-08-02 19:12 GMT+02:00 Konstantin Weitz konstantin.we...@gmail.com:

 I'm trying to write a distributed racket program using [places][0]. From
 my current understanding, this means that I have to send data to each place
 over a channel using the `place-channel-put` function, which can send any
 value accepted by `place-message-allowed?`.

 I would like to send closures over a channel, unfortunately, closures are
 not accepted by `place-message-allowed?`. Is there any way to serialize a
 closure into a value accepted by a channel, and then deserialize it on the
 other side of the channel?


 How many lambda expressions are we talking about?
 If the number is limited you can defined custom closures.

 Whether or not the following is practical I will leave up to you
 to decide :-)


 Consider this program.

 (define x 3)
 (define f (lambda (y) (+ x y)))
 (f 4)

 Annotate the free variables of the lambda-expression.

 (define x 3)
 (define f (lambda (y) (+ x y)))  ; x is free
 (f 4)

 Define an explicit closure struct and a helper to access free variables.

 (struct closure (code free) #:prefab)

 The code field will refer to a closed (no free variables) version of f and
 free is a vector of the values of the free variables at the
 time the closure was created.

 The idea is that we want to replace (lambda (y) (+ x y)) with (closure
 f_closed (vector x)).

 A little helper to access the free variables:

 (define (free-ref cl i)
   (vector-ref (closure-free cl) i))

 Now define a closed (no free variables) version of f:

 (define f_closed
   (lambda (cl y)
 (let ((x (free-ref cl 0)))
   (+ x y

 We can now rewrite the lambda expression into a closure allocation.

 The full program is now:

 (struct closure (code free) #:prefab)
 (define (free-ref cl i)  (vector-ref (closure-free cl) i))

 (define f_closed
   (lambda (cl y)
 (let ((x (free-ref cl 0)))
   (+ x y

 (define x 3)
 (define f (closure f_closed (vector x)))
 (f 4)

 Note that the structure is a prefab structure in order to be a legal
 message.

 At this point there is a complication:

 * f_closed is not an allowed message
 * (f 4) fails since the closure structure is not applicable

 The first point is solved by sending the name of f_closed as a symbol.
 One could use eval to change it back to a function, but a hash table will
 do:

 (define closed-functions-ht
   (make-hasheq (list (cons 'f_closed f_closed

 (define (get-closed-function name)
   (hash-ref closed-functions-ht name
 (λ _ (error 'app no closed function of that name ~a
 name

 The other can unfortunately not be solved by turning the structure
 into an applicable struct, since prefab structures can't have properties.
 Therefore we need to introduce a construct app that knows how to invoke
 closures.

 (define-syntax-rule (app cl arg ...)
   ((get-closed-function (closure-code cl)) cl arg ...))

 The entire program is now:

 #lang racket
 (struct closure (code free) #:prefab)
 (define (free-ref cl i)  (vector-ref (closure-free cl) i))

 (define f_closed
   (lambda (cl y)
 (let ((x (free-ref cl 0)))
   (+ x y

 (define closed-functions-ht
   (make-hasheq (list (cons 'f_closed f_closed

 (define (get-closed-function name)
   (hash-ref closed-functions-ht name
 (λ _ (error 'app no closed function of that name ~a
 name

 (define-syntax-rule (app cl arg ...)
   ((get-closed-function (closure-code cl)) cl arg ...))

 (define x 3)
 (define f (closure 'f_closed (vector x)))
 (app f 4)

 The value of f is:

  f
 '#s(closure f_closed #(3))

 and that value is an allowed message.

 The standard higher operations such as map and apply do not know about the
 special calling convention of f, so (map f '(1 2 3)) will not work.
 It is no big deal though, since wrapping f in a lambda works:

  (map (λ (x) (app f x))
'(1 2 3))
 '(4 5 6)

 To make this solution practical one could introduce a macro Lambda
 that turns (Lambda (x) (y) (+ x y)) into (closure 'closed1 (vector x)))
 and at the same time lifts

 (define closed1
   (lambda (cl y)
 (let ((x (free-ref cl 0)))
   (+ x y

 to the top of the program.

 An ambitious solution would also use free-vars from syntax/free-vars
 to determine the free variables automatically.

 /Jens Axel




-- 
-- 
Jens Axel Søgaard

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

Re: [racket-users] eval PSA (was Sending Closures to Places)

2015-08-03 Thread Jens Axel Søgaard
On eval in dynamic languages generally and in Racket specifically
http://blog.racket-lang.org/2011/10/on-eval-in-dynamic-languages-generally.html
Posted by Matthew Flatt
http://blog.racket-lang.org/2011/10/on-eval-in-dynamic-languages-generally.html



2015-08-03 13:32 GMT+02:00 Josh Grams j...@qualdan.com:

 On 2015-08-03 01:22AM, Neil Van Dyke wrote:
  Eval might indeed be the perfect solution this time, iff every other
  conceivable alternative has been rejected. :)
 
  Shameless link to PSA on the topic of eval:
  http://lists.racket-lang.org/users/archive/2014-July/063597.html
 
  Suggestions for other forms for PSA are welcome:

 If people knew *why* and *how* to avoid eval, wouldn't they already be
 doing it? To be useful to your target audience, I think you *need* to
 back this up with a link to supporting documentation. I'd be looking
 for:

 - A *brief* high-level statement of why eval causes problems: maybe
   something like this? I'm sure there are better statements out there...

   eval takes code which was constructed in one context and assigns
   meaning to it in a different context. This can cause the code to have
   an unexpected meaning, or fail to work altogether. It can also cause
   security problems (if you pass it code from an untrusted source) or be
   unnecessarily slow (evaluating code at runtime which could have been
   fixed at compile time).

 - Rules of thumb for how to decide what to use instead, and when eval
   might be ok. This answer (http://stackoverflow.com/a/2571549/2426692)
   suggests asking:

   - Do I really need eval or does the compiler/evaluator already do what
 I want?
   - Does the code really need to be constructed at runtime or can it be
 constructed earlier?
   - Will funcall, reduce, or apply work instead?

 - Concrete examples of where beginners tend to use eval and how to code
   them without it. This is sort of the same as the previous one, but I
   like to see a short overview of the whole strategy by itself, so I
   would put the examples separately, e.g. HTDP has a *nice* clear
   overview of the design recipe, whereas HTDP 2e has no place where you
   can go for a quick refresher of what were the steps of the design
   recipe again?

 -

 That's my two cents. I always see these sorts of things getting brushed
 off as unhelpful or even patronizing, so I think you want to go out of
 your way to make it easy to dig into it and reach successively deeper
 levels of understanding.

 --Josh

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Macro that does substitution

2015-07-29 Thread Jens Axel Søgaard
Something like this:

#lang racket
(require (for-syntax syntax/parse racket/syntax))

(define-syntax (let-cbn stx)
  (syntax-parse stx
[(_let-cbn ([x:id e:expr] ...) body)
 ;; For each identifier x we need a new identifier bound to (λ () e)
 (define/with-syntax (x* ...) (generate-temporaries #'(x ...)))
 (syntax/loc stx
   (let ([x* (λ () e)] ...)
 ;; in the boby we need to rewrite x to (x*)
 ;; we need to handle references, applications and assignments
 (let-syntax ([x (λ (so)
   (syntax-parse so
 #:literals (set!)
 [_x:id (syntax/loc so (x*))]
; reference to x*
 [(_x:id e ...) (syntax/loc so ((x*) e ...))]
; application
  [(set! _ __)  ; assignment
   (raise-syntax-error
'let-cbn assignment to cbn variable not
allowed #'stx so)]))]
  ...)
   body)))]))

 (let-cbn ([x 0] [y (/ 1 0)]) x)
0

 (let-cbn ([x 0] [y (/ 1 0)]) y)
/: division by zero


2015-07-29 15:28 GMT+02:00 Klaus Ostermann klaus...@gmail.com:

 I'd like to have a macro let-cbn which does this:

 (let-cbn ((x1 e1) ...) body)

 is transformed to

 (let ((x1 (thunk e1)) ...) newbody)

 where newbody is the result of replacing every occurence of x1... by
 (x1)... .

 What is the best way to do that in Racket?

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




-- 
-- 
Jens Axel Søgaard

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


[racket-users] How to break a process created with system

2015-08-09 Thread Jens Axel Søgaard
Hi All,

The function node below takes the path of a JavaScript file, starts
node (JavaScript evaluator) using system. The output is
collected in a string.

(define (node path)
  (with-output-to-string
  (λ ()
(system (string-append /usr/local/bin/node(path-string
path))

The function is used from within DrRacket. If the JavaScript program doesn't
terminate, I use cmd-b to break the process. Control is given back to the
repl, but the node system process keeps running in the background - and
needs to be killed manually.

How can I kill the node system process from within DrRacket?

One of my attempts that didn't work:

(define (node path)
  (with-output-to-string
  (λ ()
(parameterize ([current-subprocess-custodian-mode 'kill]
   [subprocess-group-enabled  #t])
  (system (string-append /usr/local/bin/node   
(path-string path)))

-- 
Jens Axel Søgaard

-- 
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 break a process created with system

2015-08-09 Thread Jens Axel Søgaard
2015-08-09 15:24 GMT+02:00 Matthew Flatt mfl...@cs.utah.edu:

 Does `(current-subprocess-custodian-mode 'kill)` combined with Cmd-k
 (for kill, instead of break) make the subprocess terminate?


Yes.

If so, you could use `dynamic-wind` or catch `exn:break` exceptions,
 possibly put the subprocess under its own custodian, and so on.


Thanks that worked. For the archives:

(define (node/break path)
  (define me(current-thread))
  (define cust  (make-custodian))
  (define (kill)(custodian-shutdown-all cust))
  (define (on-break _)  (kill) \break: node process was killed\)
  (parameterize ([current-subprocess-custodian-mode 'kill]
 [subprocess-group-enabled  #t]
 [current-custodian cust])
(with-handlers ([exn:break? on-break])
  (thread (λ() (thread-send me (node path
  (thread-receive

/Jens Axel



 At Sun, 9 Aug 2015 15:17:19 +0200, Jens Axel Søgaard wrote:
  Hi All,
 
  The function node below takes the path of a JavaScript file, starts
  node (JavaScript evaluator) using system. The output is
  collected in a string.
 
  (define (node path)
(with-output-to-string
(λ ()
  (system (string-append /usr/local/bin/node   
 (path-string
  path))
 
  The function is used from within DrRacket. If the JavaScript program
 doesn't
  terminate, I use cmd-b to break the process. Control is given back to the
  repl, but the node system process keeps running in the background - and
  needs to be killed manually.
 
  How can I kill the node system process from within DrRacket?
 
  One of my attempts that didn't work:
 
  (define (node path)
(with-output-to-string
(λ ()
  (parameterize ([current-subprocess-custodian-mode 'kill]
 [subprocess-group-enabled  #t])
(system (string-append /usr/local/bin/node   
  (path-string path)))
 
  --
  Jens Axel Søgaard
 
  --
  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.




-- 
-- 
Jens Axel Søgaard

-- 
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] Typesetting Racket code

2015-08-12 Thread Jens Axel Søgaard
How does Scribble typeset the lambda?

/Jens Axel




2015-08-12 18:15 GMT+02:00 Vincent St-Amour stamo...@eecs.northwestern.edu
:

 Paul,

 FWIW, many of us use Scribble for papers and theses, which does a great
 job at typesetting Racket code. It's also (IMO) a much more pleasant
 document authoring language than TeX.

 For example, my dissertation [1] is written using Scribble and a wrapper
 over the classicthesis style [2]. If you need to use a particular style,
 writing a similar wrapper is straighforward. In some cases, you may not
 even need a wrapper, and can just use `#lang scribble/base` and the
 ++style flag. I know that's what Burke Fetscher is doing, and it seems
 to be working well.

 Hope that helps!

 Vincent



 [1] http://users.eecs.northwestern.edu/~stamourv/papers/dissertation.pdf
 [2] https://github.com/stamourv/classicthesis-scribble
 OR raco pkg install classicthesis-scribble



 On Wed, 12 Aug 2015 09:21:30 -0500,
 Paul van der Walt wrote:
 
  Hello Racketeers,
 
  Of course, i should be doing something useful, like writing my thesis.
  Instead, i am obsessing over typesetting details.
 
  I use fixed-width fonts (the LaTeX package beramono, to be precise) for
  my code snippets.  I use the listings package too.  This allows me to
  mark words such as `lambda` as keywords, and apply special formatting to
  them.  What i would actually like, however, is to be able to use the
  symbol, literally λ, in my code.  I have managed to do that in 2
  different ways:
 
  - using $\lambda$ inline.  This gives me the math-mode font (a sort of
italicised affair) in the middle of my teletype code snippet.  That's
ugly.
 
  - using the package textgreek, since the command \textlambda it provides
respects surrounding formatting.  This means that my λ-symbols are
upright, and can be bolded following my convention in code snippets.
 
  What do i actually want, you ask?  Well, i want to be able to typeset a
  bold, upright λ symbol in my fixed-width font, such that it does not
  look out of place.  I have not quite managed to ascertain whether
  beramono includes a glyph for λ, but i thought to myself, i cannot be
  the first person having this problem.
 
  Any pointers would be appreciated.  Of note might also be that i am
  using pdfLaTeX, not XeTeX or anything else fancy.  If i *rally* have
  to i might be persuaded to move, but i am a creature of habit, so i
  would accord mad bonus points to anyone who does this without me having
  to change my workflow too much.
 
  I hope there is a solution.  Kind regards!
 
  p.
 
  PS: the included image includes an example of how my code currently
  looks.  IMHO, the λ is rather out-of-place compared to the surrounding
  \texttt{..} code.
 
  --
  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.




-- 
-- 
Jens Axel Søgaard

-- 
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] Affecting the errors generated by syntax-parse

2015-07-25 Thread Jens Axel Søgaard
Hi All,

The syntax-parse form can often generate sensible errors based on the
progress made
during the attempt to match a pattern against a syntax-object. Given
multiple choices
the choice where the maximum progress was made is used to generate the
error message.

Is there a way to tell syntax-parse, that a given choice is to be used as
the source
of the error, if the match fails?

A concrete example: In the toy language below a top-level form can be a
definition
or an expression. The malformed definition (define (foo 3) x) is not a legal
definition -- it is however clear that the user intended to write a
definition,
since the form begins with (define ...). During matching syntax-parse
makes more progress under the assumption that the definition is a sequence
expression, so the error message becomes: begin expected.

How can I stop the matching prematurely when the (define ...) is seen?

/Jens Axel

#lang racket
;;;
;;; URLANG
;;;

; In the grammar below x stands for a non-keyword identifier

; program::= top-level-form ...
; top-level-form ::= definition | expr

; definition ::= (define (x x ...) body)
; body   ::= expr

; expr   ::= datum | reference | application | sequence
; reference  ::= x
; application::= (x0 x ...)
; sequence   ::= (begin expr ...)

; keyword::= define | begin

; datum  ::= fixnum

; identifier an identifier that is not a keyword
; fixnum an integer between -2^53 and 2^53

(require syntax/parse)

(define min-fixnum (- (expt 2 53)))
(define max-fixnum(expt 2 53))

(define (Fixnum? r)
  (and (number? r) (integer? r)
   (= min-fixnum r max-fixnum)))

(define-syntax-class Fixnum
  #:opaque
  (pattern d
   #:fail-unless (Fixnum? (syntax-e #'d)) #f))

(define-syntax-class Datum
  (pattern (~or d:Fixnum)))

(define-syntax-class Keyword
  #:literals (begin define)
  (pattern (~or begin define)))

(define-syntax-class Id
  (pattern (~and x:id
 (~not y:Keyword

(define-syntax-class Reference
  (pattern x:Id))

(define-syntax-class Application
  #:literals (define)
  (pattern (e:Expr ...)))

(define-syntax-class Sequence
  #:literals (begin)
  (pattern (begin e0:Expr e:Expr ...)))

(define-syntax-class Definition
  #:literals (define)
  (pattern (define (name:Id a:Id ...) body:Body)))


(define-syntax-class Body
  (pattern b:Expr))

(define-syntax-class Expr
  (pattern (~or e:Datum
e:Application
e:Reference
e:Sequence)))

(define-syntax-class TopLevelForm
  (pattern (~or t:Definition
t:Expr)))

(define-syntax-class Program
  (pattern (p:TopLevelForm ...)))

;;; The following expressions show some legal
;;; constructs that are matched correctly.

(syntax-parse #'3
  [d:Datum 'datum])

(syntax-parse #'3
  [e:Expr 'expr])

(syntax-parse #'(define (a x) x)
  [t:TopLevelForm 'toplevelform])

(syntax-parse #'((define (foo x y) (+ x 1)) (foo 3))
  [p:Program 'program])

;;; The malformed definition (define (a 4 x) x) is
;;; correctly rejected as a toplevel form, but the
;;; automatically generated error is not as intended.

(syntax-parse #'(define (a 4 x) x)
  [t:TopLevelForm 'toplevelform])

-- 
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] Affecting the errors generated by syntax-parse

2015-07-25 Thread Jens Axel Søgaard
Hi Stephen,

Thanks for testing this. Turns out I had removed a #:opaque in Definition
while cleaning up
the example before sending the mail. Now I get the same error as you.

With

(define-syntax-class Definition
  #:opaque
  #:literals (define)
  (pattern (define (name:Id a:Id ...) body:Body)))

I get the wrong error (because #:opaque shortens the progress).

I had experimented with ~! as in:

(define-syntax-class Definition
  #:opaque
  #:literals (define)
  (pattern (define ~! (name:Id a:Id ...) body:Body)))

but the #:opaque ruins the effect of ~! here (not sure why).


Sorry for the noise,
Jens Axel



2015-07-25 16:55 GMT+02:00 Stephen Chang stch...@ccs.neu.edu:

 Actually, I dont get the begin expected error that you mention. I'm
 getting:

 define: expected identifier
   parsing context:
while parsing Id
while parsing Definition
while parsing TopLevelForm in: 4

 with the 4 highlighted, which seems correct since it comes from using
 the Definition class?

 On Sat, Jul 25, 2015 at 10:51 AM, Stephen Chang stch...@ccs.neu.edu
 wrote:
  I haven't played with the example in detail, but do you want the cut
  operator here?
 
 
 http://docs.racket-lang.org/syntax/stxparse-patterns.html?q=syntax-parse#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7e!%29%29
 
  On Sat, Jul 25, 2015 at 9:55 AM, Jens Axel Søgaard
  jensa...@soegaard.net wrote:
  Hi All,
 
  The syntax-parse form can often generate sensible errors based on the
  progress made
  during the attempt to match a pattern against a syntax-object. Given
  multiple choices
  the choice where the maximum progress was made is used to generate the
  error message.
 
  Is there a way to tell syntax-parse, that a given choice is to be used
 as
  the source
  of the error, if the match fails?
 
  A concrete example: In the toy language below a top-level form can be a
  definition
  or an expression. The malformed definition (define (foo 3) x) is not a
 legal
  definition -- it is however clear that the user intended to write a
  definition,
  since the form begins with (define ...). During matching syntax-parse
  makes more progress under the assumption that the definition is a
 sequence
  expression, so the error message becomes: begin expected.
 
  How can I stop the matching prematurely when the (define ...) is seen?
 
  /Jens Axel
 
  #lang racket
  ;;;
  ;;; URLANG
  ;;;
 
  ; In the grammar below x stands for a non-keyword identifier
 
  ; program::= top-level-form ...
  ; top-level-form ::= definition | expr
 
  ; definition ::= (define (x x ...) body)
  ; body   ::= expr
 
  ; expr   ::= datum | reference | application |
 sequence
  ; reference  ::= x
  ; application::= (x0 x ...)
  ; sequence   ::= (begin expr ...)
 
  ; keyword::= define | begin
 
  ; datum  ::= fixnum
 
  ; identifier an identifier that is not a keyword
  ; fixnum an integer between -2^53 and 2^53
 
  (require syntax/parse)
 
  (define min-fixnum (- (expt 2 53)))
  (define max-fixnum(expt 2 53))
 
  (define (Fixnum? r)
(and (number? r) (integer? r)
 (= min-fixnum r max-fixnum)))
 
  (define-syntax-class Fixnum
#:opaque
(pattern d
 #:fail-unless (Fixnum? (syntax-e #'d)) #f))
 
  (define-syntax-class Datum
(pattern (~or d:Fixnum)))
 
  (define-syntax-class Keyword
#:literals (begin define)
(pattern (~or begin define)))
 
  (define-syntax-class Id
(pattern (~and x:id
   (~not y:Keyword
 
  (define-syntax-class Reference
(pattern x:Id))
 
  (define-syntax-class Application
#:literals (define)
(pattern (e:Expr ...)))
 
  (define-syntax-class Sequence
#:literals (begin)
(pattern (begin e0:Expr e:Expr ...)))
 
  (define-syntax-class Definition
#:literals (define)
(pattern (define (name:Id a:Id ...) body:Body)))
 
 
  (define-syntax-class Body
(pattern b:Expr))
 
  (define-syntax-class Expr
(pattern (~or e:Datum
  e:Application
  e:Reference
  e:Sequence)))
 
  (define-syntax-class TopLevelForm
(pattern (~or t:Definition
  t:Expr)))
 
  (define-syntax-class Program
(pattern (p:TopLevelForm ...)))
 
  ;;; The following expressions show some legal
  ;;; constructs that are matched correctly.
 
  (syntax-parse #'3
[d:Datum 'datum])
 
  (syntax-parse #'3
[e:Expr 'expr])
 
  (syntax-parse #'(define (a x) x)
[t:TopLevelForm 'toplevelform])
 
  (syntax-parse #'((define (foo x y) (+ x 1)) (foo 3))
[p:Program 'program])
 
  ;;; The malformed definition (define (a 4 x) x) is
  ;;; correctly rejected as a toplevel form, but the
  ;;; automatically generated error is not as intended.
 
  (syntax-parse #'(define (a 4 x) x)
[t:TopLevelForm 'toplevelform])
 
  --
  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

[racket-users] sub-range-binders

2015-07-14 Thread Jens Axel Søgaard
Hi All,

I am experimenting with the sub-range-binders syntax property.

Given this program:

(define symb? symbol?)
(define-no? symb?)
symb

I want to use DrRacket's renaming facility to rename the symb? in the
second line to sym?.

I expect to get this program:

(define sym? symbol?)
(define-no? sym?)
sym

However I get this:

(define sym? symbol?)
(define-no? sym?)
sym?

(notice the extra ? in the last line).

Is this possible using sub-range-binders ?

/Jens Axel


#lang racket/base
(require (for-syntax racket/base))
(define-syntax (define-no? stx)
  (syntax-case stx ()
[(_ id?)
 (let ()
   (define s (symbol-string (syntax-e #'id?)))
   (define l1 (string-length s))
   (define l2 (- l1 1))
   (define id-str (substring s 0 l2))
   (define id (datum-syntax #'id? (string-symbol id-str)))

   (syntax-property #`(define #,id id?)
'sub-range-binders (vector (syntax-local-introduce
id)
   0 l2 0.5 0.5
   (syntax-local-introduce
#'id?)
   0 l1 0.5 0.5)))]))

(define symb? symbol?)
(define-no? symb?)
symb

-- 
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: My son's game in Racket

2015-08-25 Thread Jens Axel Søgaard
Hi,

Does G, T, and H work for you in DrRacket ?

/Jens Axel


2015-08-25 15:59 GMT+02:00 Mr Susnake susn...@gmail.com:

 On Monday, August 24, 2015 at 10:28:07 PM UTC+6, John Carmack wrote:
  We “released” my 10 year old son’s game that was done in Racket:
  www.1k3c.com
 
 
 
  I’m still taking a little heat from my wife for using an obscure
 language instead of something mainstream that is broadly used in industry,
 but I have nothing but good things to say about using Racket and DrRacket
 for a beginning programmer,
   and highly recommend it.
 
 
 
  I can’t recommend 2htdp/universe for this sort of thing, though.  I had
 to drop to the native GUI bitmaps for performance reasons, hack around the
 lifecycle to support a separate editor window, and I still don’t know how
 to make the Quit
   menu item actually exit the app on the Mac version.
 
 
 
  I completely understand the reasoning for the way 2htdp/universe is
 built, and saying that a “real” project should use the grown-up APIs is
 fine, but the evolution from making a little animation to controlling it
 somehow to fleshing it
   out into a game is so natural that recommending a fairly big rewrite is
 unfortunate.
 
 
 
  I’m a big booster of functional programming, but I’m not sure that the
 functional drawing paradigm ever really sank in while my son was working
 with it, rather it felt like you just drew everything backwards with
 missing parenthesis at
   the end.  I suspect that using the standard imperative GUI drawing code
 will make perfect sense to him.
 
 
 
  I’m not sure yet if we are going to migrate to the regular GUI code for
 upcoming work, or jump all the way to OpenGL so he can learn the joys of
 “Why is the screen all black?”
 
 

 Good day. Thank you for this game.
 I found one little bug:
 I have Windows 10  and das keyboard model s and when i want to press
 G or T, or H  it's doesn't work.

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




-- 
-- 
Jens Axel Søgaard

-- 
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: My son's game in Racket

2015-08-25 Thread Jens Axel Søgaard
DrRacket is the programming environment used to build the game.

Download it here: http://download.racket-lang.org/

Test the keys and let us know if they work or not.

/Jens Axel



2015-08-25 16:08 GMT+02:00 Mr Susnake susn...@gmail.com:

 On Tuesday, August 25, 2015 at 8:03:43 PM UTC+6, Jens Axel Søgaard wrote:
  Hi,
 
 
  Does G, T, and H work for you in DrRacket ?
 
 
  /Jens Axel
 
 
 
 
  2015-08-25 15:59 GMT+02:00 Mr Susnake sus...@gmail.com:
  On Monday, August 24, 2015 at 10:28:07 PM UTC+6, John Carmack wrote:
 
   We “released” my 10 year old son’s game that was done in Racket:
 
   www.1k3c.com
 
  
 
  
 
  
 
   I’m still taking a little heat from my wife for using an obscure
 language instead of something mainstream that is broadly used in industry,
 but I have nothing but good things to say about using Racket and DrRacket
 for a beginning programmer,
 
and highly recommend it.
 
  
 
  
 
  
 
   I can’t recommend 2htdp/universe for this sort of thing, though.  I
 had to drop to the native GUI bitmaps for performance reasons, hack around
 the lifecycle to support a separate editor window, and I still don’t know
 how to make the Quit
 
menu item actually exit the app on the Mac version.
 
  
 
  
 
  
 
   I completely understand the reasoning for the way 2htdp/universe is
 built, and saying that a “real” project should use the grown-up APIs is
 fine, but the evolution from making a little animation to controlling it
 somehow to fleshing it
 
out into a game is so natural that recommending a fairly big rewrite
 is unfortunate.
 
  
 
  
 
  
 
   I’m a big booster of functional programming, but I’m not sure that the
 functional drawing paradigm ever really sank in while my son was working
 with it, rather it felt like you just drew everything backwards with
 missing parenthesis at
 
the end.  I suspect that using the standard imperative GUI drawing
 code will make perfect sense to him.
 
  
 
  
 
  
 
   I’m not sure yet if we are going to migrate to the regular GUI code
 for upcoming work, or jump all the way to OpenGL so he can learn the joys
 of “Why is the screen all black?”
 
  
 
  
 
 
 
  Good day. Thank you for this game.
 
  I found one little bug:
 
  I have Windows 10  and das keyboard model s and when i want to press
 G or T, or H  it's doesn't work.
 
 
 
 
 
  --
 
  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...@googlegroups.com.
 
  For more options, visit https://groups.google.com/d/optout.
 
 
 
 
 
  --
 
  --
  Jens Axel Søgaard
 Thank you for reply.
 DrRacket? What is it?

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




-- 
-- 
Jens Axel Søgaard

-- 
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] Interpolating Polynomial in Newton Form

2015-11-10 Thread Jens Axel Søgaard
Use Horner's rule.

/Jens Axel


2015-11-06 22:27 GMT+01:00 Dave Yrueta <dyru...@gmail.com>:

> Hi All —
>
> Given a list of constants (a0, a1… an) and a list of x-values (x0,
> x1,….xn), I want to write a function in Racket that produces the function
> p(x) = a0 + a1(x - x0) + a2(x - x0)(x - x1) + a3(x - x0)(x - x1) (x - x2) +
> ….+ an(x - x0)(x - x1)…(x - xn), or the interpolating polynomial in Newton
> form.   My understanding of functions that produce functions is limited to
> what’s in HtDP, and this example (I think) goes beyond that.  Any tips or
> advice would be much appreciated!
>
> Cheers,
> Dave Yrueta
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Feasibility of Racket for scientific and engineering calculations

2015-11-10 Thread Jens Axel Søgaard
A few useful resources:

Matrices
http://docs.racket-lang.org/math/matrices.html?q=matrix

GNU Scientific Library

http://planet.racket-lang.org/package-source/wmfarr/mzgsl.plt/3/0/planet-docs/mzgsl/index.html

Science Collection

http://planet.racket-lang.org/package-source/williams/science.plt/4/8/planet-docs/science/index.html

Math library
http://docs.racket-lang.org/math/index.html?q=matrix

Also: If you are looking for concrete algorithms - just ask. Chances are
that
someone has a Racket and/or Scheme implementation lying around.

If you are interested in symbolic computations I have a few ideas.

/Jens Axel


2015-11-03 2:15 GMT+01:00 John Kitchin <johnrkitc...@gmail.com>:

> Hi all,
>
> I am exploring whether Racket could be a Lisp replacement for Python in
> scientific and engineering calculations. I currently use Python extensively
> in teaching chemical engineering courses (
> http://kitchingroup.cheme.cmu.edu/pycse/) and in running molecular
> simulations (http://kitchingroup.cheme.cmu.edu/dft-book/), but I am
> interested in transitioning these to a Lisp.
>
> Why? Because I really like writing Lisp code, and some interesting things
> I can do with it. My current experience is all with emacs-lisp, which at
> the moment has no hope for replacing Python as it lacks a real ffi.
>
> Python works for scientific/engineering calculations because of
> numpy/scipy/matplotlib which provide the majority of our needs, and largely
> they just wrap C/Fortran numerical libraries. It is also distributed with
> batteries included that make it trivial to install these days. It seems
> like Racket can do this too.
>
> How feasible would it be to use Racket to solve the problems described
> here: http://kitchingroup.cheme.cmu.edu/pycse/pycse.pdf
>
> I am trying to gauge how difficult it would be to start using Racket for
> these problems. Does anyone know of any similar kinds of projects as my
> Python project above in Racket?
>
> Thanks!
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Feasibility of Racket for scientific and engineering calculations

2015-11-12 Thread Jens Axel Søgaard
Hi Marc,

Take a look at:

https://github.com/soegaard/racket-cas

Start with the readme and play with a few examples.

Skim (later parts) of:


https://github.com/soegaard/racket-cas/blob/master/racket-cas/racket-cas.rkt

to see what's implemented.

Any bug reports and comments are welcome.

/Jens Axel



2015-11-12 17:26 GMT+01:00 Marc Kaufmann <marc.kaufman...@gmail.com>:

> Since you mention symbolic computations: is there anything that does
> symbolic differentiation in Racket - I know Maxima is written in Common
> Lisp. I would I would be happy with only differentiation and little of the
> other stuff, if only to check my own computations (in economics) as I have
> perform a sign-error in 25% of the cases...
>
> On Tuesday, November 10, 2015 at 10:34:50 PM UTC-5, John Kitchin wrote:
> > Those are great resources! Thanks!
> >
> > Jens Axel Søgaard writes:
> >
> > > A few useful resources:
> > >
> > > Matrices
> > > http://docs.racket-lang.org/math/matrices.html?q=matrix
> > >
> > > GNU Scientific Library
> > >
> > >
> http://planet.racket-lang.org/package-source/wmfarr/mzgsl.plt/3/0/planet-docs/mzgsl/index.html
> > >
> > > Science Collection
> > >
> > >
> http://planet.racket-lang.org/package-source/williams/science.plt/4/8/planet-docs/science/index.html
> > >
> > > Math library
> > > http://docs.racket-lang.org/math/index.html?q=matrix
> > >
> > > Also: If you are looking for concrete algorithms - just ask. Chances
> are
> > > that
> > > someone has a Racket and/or Scheme implementation lying around.
> > >
> > > If you are interested in symbolic computations I have a few ideas.
> > >
> > > /Jens Axel
> > >
> > >
> > > 2015-11-03 2:15 GMT+01:00 John Kitchin:
> > >
> > >> Hi all,
> > >>
> > >> I am exploring whether Racket could be a Lisp replacement for Python
> in
> > >> scientific and engineering calculations. I currently use Python
> extensively
> > >> in teaching chemical engineering courses (
> > >> http://kitchingroup.cheme.cmu.edu/pycse/) and in running molecular
> > >> simulations (http://kitchingroup.cheme.cmu.edu/dft-book/), but I am
> > >> interested in transitioning these to a Lisp.
> > >>
> > >> Why? Because I really like writing Lisp code, and some interesting
> things
> > >> I can do with it. My current experience is all with emacs-lisp, which
> at
> > >> the moment has no hope for replacing Python as it lacks a real ffi.
> > >>
> > >> Python works for scientific/engineering calculations because of
> > >> numpy/scipy/matplotlib which provide the majority of our needs, and
> largely
> > >> they just wrap C/Fortran numerical libraries. It is also distributed
> with
> > >> batteries included that make it trivial to install these days. It
> seems
> > >> like Racket can do this too.
> > >>
> > >> How feasible would it be to use Racket to solve the problems described
> > >> here: http://kitchingroup.cheme.cmu.edu/pycse/pycse.pdf
> > >>
> > >> I am trying to gauge how difficult it would be to start using Racket
> for
> > >> these problems. Does anyone know of any similar kinds of projects as
> my
> > >> Python project above in Racket?
> > >>
> > >> Thanks!
> > >>
> > >> --
> > >> 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.
> > >>
> > >
> > >
> > >
> > > --
> >
> > --
> > Professor John Kitchin
> > Doherty Hall A207F
> > Department of Chemical Engineering
> > Carnegie Mellon University
> > Pittsburgh, PA 15213
> > 412-268-7803
> > @johnkitchin
> > http://kitchingroup.cheme.cmu.edu
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Puzzle

2015-10-12 Thread Jens Axel Søgaard
In DrRacket with just #lang racket in the definitions window.
Click Run.

Welcome to DrRacket, version 6.3.0.1--2015-10-12(a683542/a) [3m].
Language: racket; memory limit: 1024 MB.

> (syntax->datum (expand #'(begin (define (sort v) v) (sort t
'(begin (define-values (sort) (lambda (v) v)) (#%app sort9 t))

Notice that the identifiers sort and sort9 in the expansion are different.

Why?

/Jens Axel

-- 
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] Syntax parse and optional patterns

2015-07-11 Thread Jens Axel Søgaard
Hi All,

Is there a simpler way of defining the syntax transformation (macro) below?

/Jens Axel


#lang racket
(require (for-syntax syntax/parse racket/syntax))

(provide let-match-expander)

;;; SYNTAX (let-match-expander ([id proc0 proc1] ...) body ...)
;;;(let-match-expander ([id proc0]   ...) body ...)
;;; Bind id ... to a match expanders in body ...
;;; The procedure sub-expressions proc0 and proc1 are similar to
;;; the procedure sub-expressions of define-match-expander.

;;; EXPANSION STRATEGY
;;;   Use define-match-expander to bind the match-expanders to fresh names.
;;;   Use let-syntax to bind them in the body.

(define-syntax (let-match-expander stx)
  ; the procs attribute of optional-proc1 will always be a list,
  ; which means that we can use proc1.procs ... in a template
  (define-splicing-syntax-class optional-proc1
(pattern (~seq proc1:expr) #:with procs #'(proc1))
(pattern (~seq)#:with procs #'()))

  (syntax-parse stx
[(_let-match-expander ((~and clause [id:id proc0:expr
proc1:optional-proc1]) ...) body ...+)
 ;; For each identifier id we need a fresh name:
 (define fresh-names (generate-temporaries #'(id ...)))
 (with-syntax ([(fresh-name ...) fresh-names]
   [((proc ...) ...) #'(proc1.procs ...)])
   (syntax/loc stx
 (begin
   ;; define a match expander for each id
   (define-match-expander fresh-name proc0 proc ...) ...
   ;; make the match expander known inside the body
   (let-syntax ([id (syntax-local-value #'fresh-name)] ...)
 body ...]
;; catch various errors:
;;   - missing body
[(_let-match-expander ((~and clause [id proc0 proc1:optional-proc1])
...))
 (raise-syntax-error 'let-match-expander bad syntax (missing body)
stx)]
;;   - wrong binding clause
[(_let-match-expander (clause ...) body ...)
 (for ([c (syntax-list #'(clause ...))])
   (syntax-parse c
 [(id:id proc0:expr (~optional proc1:expr)) 'ok]
 [_ (raise-syntax-error
 'let-match-expander
 expected clause of the form [id proc-expr] or [id proc0-expr
proc1-expr] c)]))
 (raise-syntax-error 'let-match-expander bad syntax stx)]))


(module+ test (require rackunit)

  (let-match-expander
   ([foo (λ (pat) (syntax-parse pat [(_foo f ...) #'(list f ...)]))
 (λ (stx) #'42)]
[bar (λ (pat) (syntax-parse pat [(_bar f ...) #'(vector f ...)]))])

   (check-equal? (match (list 1 2 3) [(foo a b c) (vector a b c)]) '#(1 2
3))
   (check-equal? (foo) 42)
   (check-equal? (match (vector 1 2 3)
   [(foo a b c) (vector a b c)]
   [(bar a b c) (list a b c)])
 '(1 2 3

-- 
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] namespace-undefine-variable! question

2015-08-27 Thread Jens Axel Søgaard
The issue here is whether the namespance's identifier mapping is used or
not.

The documentation for namespace-undefine-variable! says:

Removes the sym variable, if any, in the top-level environment of
namespace in
its base phase
file:///Applications/Racket%20v6.2/doc/reference/syntax-model.html?q=namespace-va#%28tech._base._phase%29.
The namespace’s identifier
file:///Applications/Racket%20v6.2/doc/reference/syntax-model.html?q=namespace-va#%28tech._identifier%29
mapping
(see Namespaces
file:///Applications/Racket%20v6.2/doc/reference/syntax-model.html?q=namespace-va#%28part._namespace-model%29)
is
 unaffected.

We can see that  list  is use the identifier mapping by changing the second
argument of namespace-variable-value to #f.

#lang racket
(define ns (make-base-namespace))
(namespace-variable-value 'list #f (λ () 'not-found) ns)

which evaluates to 'not-found.

Inserting your own non-imported value for  list  makes the identifier
non-imported and has
the happy side-effect of making namespace-undefined-variable! capable of
removing the
binding from namespace.

In some sense  namespace-undefined-variable!  miss an map? argument.
Your solution: insert, then undefine  seem to be the best solution for now.

/Jens Axel

you n


2015-08-27 16:53 GMT+02:00 Jos Koot jos.k...@gmail.com:

 The following works:

 #lang racket/base
 #;1 (define ns (make-base-namespace))
 #;2 (namespace-variable-value 'list #t (λ () 'not-found) ns)
 ; - #procedure:print-syntax-width
 #;3 (namespace-set-variable-value! 'list 'whatever (λ () #f) ns)
 #;4 (namespace-undefine-variable! 'list ns)
 #;5 (namespace-variable-value 'list#t (λ () 'not-found) ns)
 ; - not-found

 But when I omit line 3 it does not work:

 #lang racket/base
 #;1 (define ns (make-base-namespace))
 #;2 (namespace-variable-value 'list #t (λ () 'not-found) ns) ; -
 #procedure:list
 #;4 (namespace-undefine-variable! 'list ns)
 ;- error namespace-undefine-variable!: given name is not defined
 ;   name: list

 This I did with: Welcome to DrRacket, version
 6.2.0.5--2015-07-06(d6fa581/a) [3m].
 Code in the definitions window. The problem is not typical for 'list only.
 The same happens with (at least some) other variables of a base-namespace.

 I have no clue why commenting out line 3 gives an error.
 Do I misinterpret the docs on namespaces?

 Thanks, Jos

 PS I use a base-namespace in a toy interpreter.
 It allows me to easily borrow all variables from a base-namespace.
 But some of them I want to undefine.




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




-- 
-- 
Jens Axel Søgaard

-- 
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 on coding finite state automata

2015-09-04 Thread Jens Axel Søgaard
Hi Linh,

There are many different representations of finite state machines.

If you "just" need to simulate a single machine, a simple and efficient
approach is to represent each state as a Racket function (see example
below).

#lang racket
(require racket/generator)

;; The turn-stile example from Wikipedia.
;;
https://en.wikipedia.org/wiki/Finite-state_machine#Example:_coin-operated_turnstile

;; Current State  Input   Next State   Output
;;   LOCKED   coinUNLOCKED unlock turnstile so customer can
push through
;;   LOCKED   push  LOCKED none (custome can't move through)
;; UNLOCKED   coinUNLOCKED none
;; UNLOCKED   push  LOCKED when customer is through, lock
turnstile

(define inputs '(coin push push push coin coin push))
(define get-input (sequence->generator inputs))

(define (LOCKED)
  (match (get-input)
['coin(displayln "turnstile is unlocked")
  (UNLOCKED)]
['push(displayln "you can't move through locked turnstile")
  (LOCKED)]
[_(DONE)]))

(define (UNLOCKED)
  (match (get-input)
['coin(displayln "no need to pay when the turnstile is unlocked")
  (UNLOCKED)]
['push(displayln "customer goes through, turnstile is locked")
  (LOCKED)]
[_(DONE)]))

(define (DONE)
  (displayln "no more inputs"))

(LOCKED) ; start turnstile in a locked state




2015-09-03 16:29 GMT+02:00 Linh Chi Nguyen <nguyenlinhch...@gmail.com>:

> Dear All,
> I'm a complete newbie in racket and need help in coding finite state
> machine/automata. Please pardon any of my ignorance.
>
> Thanks to this post of Tim Thornton, I see a very good way to code FSM:
> http://timthornton.net/blog/id/538fa6f2f09a16ba0674813d
>
> I'd summarise it as following:
> A finite state automaton has a number of states and each state has a name
> plus many transition rules. He structures it in racket as following:
>
> (struct automaton (current-state states))
> (struct state (name actions))
> (struct action (event result))
>
> A simple automaton can be like this:
> (define simple-fsm (fsm 'A
> (list (fstate 'A (list (action 0 'A)
>(action 1 'B)))
>   (fstate 'B (list (action 0 'B)
>(action 1 'A))
>
> The automaton is in state A which has 2 transition rules:
> - if event 1 happens, the automaton jumps to state B,
> - if event 0 happens, it stays in state A.
>
> Then he writes some functions to update the automaton after each event (in
> the post). Plus this function he omits (I guess):
> (define fsm-update-state old-fsm new-state)
>   (struct-copy automaton old-fsm [current-state new-state]))
>
> HERE IS THE QUESTION:
>
> Using this way, after each event, there'd be a NEW automaton created. So
> I'm worried about scaling. I'd like to generate 100 automata. In each
> cycle, I'd pair the automata to interact for 50 times. Which means that
> there'd be 100 new automata created for every single cycle. And I'd like to
> run at least 1000 cycles.
>
> Would there be any problem with scaling? If yes, is there a way around
> this?
>
> Any kind of comments and suggestions are welcomed and appreciated,
> Thank you really much,
> Chi
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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: Futures vs. Places for parallelizing a simple game engine

2015-09-03 Thread Jens Axel Søgaard
Hi Brian,

For this task places will be the perfect choice.

Two reasons:
  i) each place can work a on its own board (and there is no need for
shared data)
   [at least if you are not using transposition tables]
 ii) the amount of data needed to start a task from a given board is only a
few bytes,
 so the communication overhead is small

For most boards you can do this:
  for a board B and a player P to move:
generate all boards B1, B2, ... resulting from player P making one move
on board B
place the boards in a job queue
when a place signals it is ready, send a board to the place

In some situations there are very few moves available for P. In that case
you will need to
generate boards resulting from two (or more) moves before placing them in
the job queue.

/Jens Axel






2015-09-03 18:04 GMT+02:00 Brian Adkins <lojicdot...@gmail.com>:

> On Monday, August 31, 2015 at 1:27:42 PM UTC-4, Brian Adkins wrote:
> > I'm writing a Reversi/Othello game engine in Racket as a learning
> exercise. Since my macbook pro has 4 cores and 8 hardware threads, I'd like
> to see what sort of speedup I can get by parallelizing it.
> >
> > I read through chapter 20 of the Racket Guide, and I *think* places may
> be more suitable than futures for this task due to the fact that each
> compute unit will be allocating memory for the next set of moves, etc.
> >
> > Does that sound right?
>
> No opinions on this? For you experienced Racketeers, which approach would
> you choose for maximum speed?
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Lost in ellipsis depths

2015-09-02 Thread Jens Axel Søgaard
Here are two variations:

#lang racket

(require syntax/stx syntax/parse racket/syntax unstable/sequence)

(syntax-parse #'(foo a b c)
  [(f:id s:id ...)
   (define foo-s* (stx-map (λ (x) (format-id #'f "foo-~a" x)) #'(s ...)))
   (with-syntax ([(foo-s ...) foo-s*])
 #'(list foo-s ...))])


(syntax-parse #'(foo a b c)
  [(f:id s:id ...)
   (define foo-s* (for/list ([x (in-syntax #'(s ...))])
(format-id #'f "foo-~a" x)))
   (with-syntax ([(foo-s ...) foo-s*])
 #'(list foo-s ...))])


2015-09-02 13:09 GMT+02:00 Konrad Hinsen <konrad.hin...@fastmail.net>:

> Konrad Hinsen writes:
>
>  > In fact, what I want is do something like map over the ellipsis pattern,
>  > but I haven't seen any example for doing this.
>
> Well, map actually works:
>
>   (syntax-parse #'(foo a b c)
> [(f:id s:id ...)
>  (with-syntax ([(foo-s ...)
> (map (λ (x) (format-id #'f "foo-~a" x)) (syntax-e #'(s
> ...) ))])
>#'(list foo-s ...))])
>
> But is this the only solution? It looks a bit messy.
>
> Konrad.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Racket in a web page (via Whalesong)

2015-09-07 Thread Jens Axel Søgaard
2015-09-07 6:08 GMT+02:00 Anton Vodonosov <avodono...@gmail.com>:


> As far as I understand the Racket design, Whalesong is enough to bootstrap
> full Racket in a JS environment. It's a great opportunity. I would like
> very much to have an interactive lisp development where I can develop both
> server side and client side code, and to share code between client and
> server.
>

Whalesong can not bootstrap Racket.

Here is the short version of how Whalesong compiles a file foo.rkt

   1. The Whalesong compiler (running on Racket VM) reads the file foo.rkt.
   2. The standard  expand  is called.  Expand parses and expands all
constructs
producing a program without macros.
   3. The compiler now calls the standard  compile  functions which produces
   a sequence of bytecodes.
   4. The Whalesong bytecode-to-JavaScript compilers is called and a
JavaScript file is produced.
   [ 5. Any modules required by foo.rkt are also compiled ]

The problem is that the functions  expand  and  compile  are implemented in
C.
This means that it is not possible to run the bytecode-to-JavaScript
compiler on neither the expander
nor the expanded-code-to-bytecode. Two essential components are therefore
missing before
it is possible to bootstrap Racket in Whalesong.

The expander was recently reimplemented. Maybe there is hope for an
expander written in Racket
at some point.

The "selfhost" folder in the Whalesong repository was an effort to get the
Whalesong
bytecode-to-JavaScript running in the browser. That's doable - but not
enough to get a
selfhosting Racket system.

-- 
Jens Axel Søgaard

-- 
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] Expression context

2015-09-14 Thread Jens Axel Søgaard
FWIW an alternative to (let () ...) is block.

http://docs.racket-lang.org/reference/block.html?q=block

2015-09-15 0:16 GMT+02:00 John Carmack <jo...@oculus.com>:

> Is there a deep reason why defines aren’t allowed in the branches of an
> if, but are for cond / while / unless?
>
>
>
> Wrapping code in (let() …) instead of (begin …) works fine, but it is a
> strange quirk to explain to someone 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Racket Solution of String Recursive Replace

2015-09-16 Thread Jens Axel Søgaard
> (regexp-replace "B" "BBB" "A")
"ABB"
> (regexp-replace* "B" "BBB" "A")
"AAA"

Notice the star.


2015-09-16 19:21 GMT+02:00 <sagyo12341...@gmail.com>:

> Hi,
>
> I aim to write a racket script like a bash.
>
> $ echo "BBB" | sed -r 's/A/B/g'
> BBB
>
> In racket regexp module, I cannot find the solution.
> Please help me.
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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: Eval namespace revisited ...again

2015-09-26 Thread Jens Axel Søgaard
An alternative to racket/load if you need something easier to control:

#lang racket

;; Make a new namespace
(define custom-namespace (make-base-empty-namespace))

;; Fill it with relevant bindings
(parameterize ([current-namespace custom-namespace])
  (namespace-require ''#%kernel)
  (namespace-require 'racket/base)
  (namespace-require/copy 'racket/list))

;; Use it in eval
(define (custom-eval expr)
  (eval expr custom-namespace))

;; Test it
(custom-eval '(+ 1 2 3))


2015-09-26 13:56 GMT+02:00 Jukka Tuominen <jukka.tuomi...@finndesign.fi>:

>
> In case it should be of help to anyone, using #lang racket/load solved the
> problems and things run smoothly now.
>
> br, jukka
>
>
> > Hi all,
> >
> > I'm working on a generic solution to distributed computing/ IoT/ M2M/
> > scheduled task handling etc. basing on messaging. The emphasis is on
> > usability so it is essential to allow running functions identically
> > despite of where they are run. The obvious thing to expect is that when
> > sending an expression like '(+ 1 2 3) to a remote computer, it will be
> > evaluated something like (eval '(+ 1 2 3) custom-namespace) in the
> > background and returns the expected "6".
> >
> > I've seen the numerous discussions warning about namespace conflicts, but
> > as far as I understand it should be safe in Liitin environment, where I
> > intend to use it ( liitin.org ). That is, the special environment is
> > initiated always with identical start-up definitions. No new top-level
> > definitions are allowed because of Liitin's own way of dealing with
> > dynamic objects. Internal definitions, however, are allowed (say,
> internal
> > define's within lambda expressions), but those should be safe, right?
> >
> > Instead of some standard base namespace, I need to use a custom one.
> > I'v tried the following, but it doesn't seem to work:
> >
> > (define namespace (current-namespace))
> > (parameterize ((current-namespace namespace))
> >  ...
> > (eval expression namespace))
> >
> > Any suggestions on how to make this work?
> >
> > br, jukka
> >
> >
> >
>
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Defining a symbol breaks symbols?

2015-09-30 Thread Jens Axel Søgaard
2015-09-30 19:35 GMT+02:00 Lyle Kopnicky :

> Hi folks,
>
> It seems that if I (incorrectly) quote a symbol in a 'define' form, it
> breaks all symbols from that point on. I would expect instead it would give
> me an error saying that I passed the wrong sort of thing to 'define', and
> not break future use of symbols. Is this a bug?
>
> Welcome to DrRacket, version 6.2.1 [3m].
> Language: racket; memory limit: 128 MB.
> > 'foo
> 'foo
>

Note that 'foo is short for (quote foo).


> > 'bar
> 'bar
> > (define 'foo 5)
>

This is the same as

(define (quote foo) 5)

which means that you are defining a function named quote that when called
with one argument returns the number 5.


> > 'foo
> . . foo: undefined;
>

This means

(quote foo)

i.e. you are now calling the (newly defined) quote function - but the
argument foo is not defined - hence the error.


>  cannot reference an identifier before its definition
> > 'bar
> . . bar: undefined;
>  cannot reference an identifier before its definition
> >
>

Try

> '3
5

The lesson here is that at the top-level (in the REPL) it is possible to
redefine builtin syntax.

Here the shorthand ' makes it hard to spot.

/Jens Axel

-- 
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] R6RS+horizontal panel

2016-01-28 Thread Jens Axel Søgaard
2016-01-28 21:48 GMT+01:00 jmhuffle <jmhuf...@femto-st.fr>:

>Dear Racket friends,
>
>I am surprised because the following code works in "lang racket", but
> not in R6RS: in this last case, I got a contract violation for the value
> associated with "alignment within the horizontal panel. Is there a way to
> include such a horizontal panel in a program using R6RS, please?
>


> (define hp (new horizontal-panel% (parent top-level) (alignment '(left
> top
>

In R6RS '(left top) will allocate a list consisting of mutable cons cells.
In Racket '(left top) will allocate a list of immutable cons cells.

Since the GUI is implemented in Racket it expects immutable cons cells.

The easiest solution is to switch from R6RS to Racket.
However if you want to stick with R6RS, import  list  from racket/list and
use that
to create an immutable list.

-- 
Jens Axel Søgaard

-- 
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 a text editor

2016-01-31 Thread Jens Axel Søgaard
Perhaps you can get some ideas here?

https://github.com/soegaard/bracket/blob/master/gui/racket-cas.rkt#L411

It's not the best example, but I don't know of a "Notepad" application
written in Racket.

/Jens Axel


2016-01-31 20:42 GMT+01:00 Kevin Forchione <lyss...@gmail.com>:

> Hi guys,
> I’ve been perusing the documentation on Racket GUI and am interested in
> making a text editor. Is there any source code to model from? The
> documentation got me started, but there are features such as indenting,
> line numbering and keybindings that I’m interested in implementing. I’ve
> done a bit of searching online and see that we’ve got examples using the
> 2htdp packets and a VI graphical editor, but nothing that quite fits the
> bill for what I’m doing.
>
> Any pointers are appreciated!
>
> -Kevin
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] R6RS+horizontal panel

2016-01-29 Thread Jens Axel Søgaard
2016-01-29 23:12 GMT+01:00 Jean-Michel HUFFLEN <jmhuf...@femto-st.fr>:

> Jens Axel Søgaard <jensa...@soegaard.net> wrote:
>
> 2016-01-28 21:48 GMT+01:00 jmhuffle <jmhuf...@femto-st.fr>:
>>
>>Dear Racket friends,
>>>
>>>I am surprised because the following code works in "lang racket", but
>>> not in R6RS: in this last case, I got a contract violation for the value
>>> associated with "alignment within the horizontal panel. Is there a way to
>>> include such a horizontal panel in a program using R6RS, please?
>>> (...)
>>>
>> In R6RS '(left top) will allocate a list consisting of mutable cons cells.
>> In Racket '(left top) will allocate a list of immutable cons cells.
>>
>
>OK, thanks. But a point is still obscure, for me. In R6RS, if the
> library "mutable-pairs" is not used, lists are supposed to be immutable,
> aren't they? So, they are immutable because we cannot use "set-car!" and
> "set-cdr!", provided by this library, but they are not "immuable enough"
> for Racket's graphical objects... Strange...
>
>
Sorry - I am stuck back in R4RS/R5RS times where Scheme only had mutable
lists.

/Jens Axel

-- 
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] long (16s) pauses in UI associated with OS X, possibly app nap?

2016-02-22 Thread Jens Axel Søgaard
FWIW I may have seen the same thing. I am not using "automatic parentheses"
though.
I have seen it at occasion when typing a " in longish files (>1500 lines).
This was on version 6.3 (or earlier?).


2016-02-22 21:04 GMT+01:00 'John Clements' via Racket Users <
racket-users@googlegroups.com>:

> I have several students who are observing truly impressive UI delays in
> using DrRacket. Specifically, it often happens when they type a
> double-quote (“) with “automatic parentheses” enabled, and after typing the
> key, it will take more than 16 seconds for the screen to update and for the
> quotes to appear. The delay seems to be shortened significantly by clicking
> or hitting the arrow keys, and I suspect this may be related to OS X’s “app
> nap” feature, that will shut down an application when it thinks that it
> doesn’t need foreground processing.
>
> Any ideas?
>
> John
>
>
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Detect version of OS X

2016-02-24 Thread Jens Axel Søgaard
What happens if  /Library/Tex/texbin is present - but not in the path?

/Jens Axel


2016-02-24 14:34 GMT+01:00 Stephen De Gabrielle <spdegabrie...@gmail.com>:

> Thank you - very good advice - I'll have to change my pull request.
> S.
>
> On Wed, 24 Feb 2016 at 10:57, Norman Gray <nor...@astro.gla.ac.uk> wrote:
>
>>
>> Greetings
>>
>> On 23 Feb 2016, at 20:46, Jens Axel Søgaard wrote:
>>
>> > Use case: The paths to LaTeX has changed on El Capitan,
>> > which makes it difficult to choose a default path, that works
>> > for all.
>>
>> Addressing that particular use-case (following the motto that one should
>> test the functionality rather than switch on the version), and if a
>> system call is OK, then adapting Stephen De Gabrielle's example you
>> could try
>>
>> #lang racket/base
>> (require racket/system racket/port)
>>
>> (let-values (((base name must-be-dir?)
>>(split-path
>> (string->path
>>  (with-output-to-string (λ ()
>>   (system "which tex")))
>>(printf "binaries in ~a~%" base))
>>
>> or call out to "tlmgr conf" or one of its subcommands (if your
>> installation is based on TeXLive).  This would obviously work on other
>> unixes, and there might be a path-searching equivalent on Windows, too.
>>
>> All the best,
>>
>> Norman
>>
>>
>> --
>> Norman Gray  :  https://nxg.me.uk
>> SUPA School of Physics and Astronomy, University of Glasgow, UK
>>
>> --
>> 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.
>>
>


-- 
-- 
Jens Axel Søgaard

-- 
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] long (16s) pauses in UI associated with OS X, possibly app nap?

2016-02-22 Thread Jens Axel Søgaard
I don't see for that file.

If I remember correctly it happened in this file:
https://github.com/soegaard/urlang/blob/master/urlang.rkt
I can't reproduce it now though (which btw is the reason I didn't report a
bug).
Hmm. Maybe it went away when I disabled background expansion?
That file is very macro heavy.

2016-02-22 22:30 GMT+01:00 Robby Findler <ro...@eecs.northwestern.edu>:

> That sounds like something that is fixable and it would be helpful to
> have a file that exhibits particularly bad problems in order to make
> sure it really is fixed.
>
> I tried opening drracket/private/unit (using "Open Require Path...")
> and wasn't able to provoke the bad behavior.
>
> Do you (or Jens Axel) see it for that file?
>
> Robby
>
> On Mon, Feb 22, 2016 at 2:04 PM, 'John Clements' via Racket Users
> <racket-users@googlegroups.com> wrote:
> > I have several students who are observing truly impressive UI delays in
> using DrRacket. Specifically, it often happens when they type a
> double-quote (“) with “automatic parentheses” enabled, and after typing the
> key, it will take more than 16 seconds for the screen to update and for the
> quotes to appear. The delay seems to be shortened significantly by clicking
> or hitting the arrow keys, and I suspect this may be related to OS X’s “app
> nap” feature, that will shut down an application when it thinks that it
> doesn’t need foreground processing.
> >
> > Any ideas?
> >
> > John
> >
> >
> >
> > --
> > 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Detect version of OS X

2016-02-23 Thread Jens Axel Søgaard
Hi All,

The function system-type can be used to detect the system type.
Is there a function that returns the version of the operating system?

Use case: The paths to LaTeX has changed on El Capitan,
which makes it difficult to choose a default path, that works
for all.

/Jens Axel

-- 
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] Detect version of OS X

2016-02-23 Thread Jens Axel Søgaard
The system-type approach looks like this (it ignores the optional third
version counter):

(match (regexp-match #px".*Kernel Version ([\\d]+[.][\\d]+).*"
(system-type 'machine))
  [(list _ version-str) (string->number version-str)]
  [_ #f])

The expression returns 15.0 on my machine.

The AppKit approach seems to be less likely to break over time?

/Jens Axel



2016-02-23 22:23 GMT+01:00 Matthew Flatt <mfl...@cs.utah.edu>:

> You could parse the result of `(system-type 'machine)`, but you might
> just as well use a little `ffi/unsafe` binding to get
> `NSAppKitVersionNumber`:
>
>  #lang racket/base
>  (require ffi/unsafe)
>
>  (define appkit
>(ffi-lib "/System/Library/Frameworks/AppKit.framework/AppKit"))
>  (define NSAppKitVersionNumber
>(and appkit (get-ffi-obj 'NSAppKitVersionNumber appkit _double)))
>
>  (define (version-10.11-or-later?)
>(NSAppKitVersionNumber . >= . 1389))
>
>
> At Tue, 23 Feb 2016 21:46:55 +0100, Jens Axel Søgaard wrote:
> > Hi All,
> >
> > The function system-type can be used to detect the system type.
> > Is there a function that returns the version of the operating system?
> >
> > Use case: The paths to LaTeX has changed on El Capitan,
> > which makes it difficult to choose a default path, that works
> > for all.
> >
> > /Jens Axel
> >
> > --
> > 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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: ispell

2016-02-29 Thread Jens Axel Søgaard
spell is a dictionary library that you can download over here:
>>>> http://aspell.net/win32/
>>>>
>>>> --
>>>> 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.
>>>>
>>> --
>>> Kind regards,
>>> Stephen
>>> --
>>> Bigger than Scheme, cooler than Clojure & more fun than CL.(n=1)
>>> --
>>>
>> --
>> Kind regards,
>> Stephen
>> --
>> Bigger than Scheme, cooler than Clojure & more fun than CL.(n=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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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 Jens Axel Søgaard
2016-02-22 22:46 GMT+01:00 Federico Ramírez <fedekil...@gmail.com>:

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

You can use this strategy:

(define (tokenize input)
  (cond
((match-identifier input)=> (lambda (token) ... consume the
identifier token...))
((match-equals input)   => (lambda (token) ... consume the
equals token...))
((match-number input) => (lambda (token) ... consume the number
token...))
(else '(

Here a clause of the form [expression1 => expression2] will calls the
result of expression2
with the result of expression1 as input. That is: when (match-identifier
input) returns a token
the function (lambda (token) ... consume the identifier token...) will be
called with the token.
Given the token you can find it's length n and then skip n bytes of the
input stream.

-- 
Jens Axel Søgaard

-- 
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] DrRacket Coverage

2016-02-15 Thread Jens Axel Søgaard
2016-02-14 19:09 GMT+01:00 Eli Barzilay :

> Every semester there are always students that think that DrRacket is
> broken when they add tests and the coverage colors go away.  I now tell
> them about it in advance (in class and in text), but it's still
> confusing people.
>
> So in the spirit of phone apps which teach you about themselves, how
> about something like a dialog popping up when coverage is enabled, and
> there is a non-trivial program, and there's complete coverage.
> Something like a short explanation of how the colors are the same since
> your code is completely covered, with a "got it" button to dismiss it.
>

How about displaying a legend in the form of an overlay in the right upper
corner.
I am thinking something like the blue documentation overlay.

/Jens Axel

-- 
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] Unicode subscripts in code and scribble

2016-03-10 Thread Jens Axel Søgaard
That reminds me:

In DrRacket \epsilon is displayed the same way \varepsilon is.

/Jens Axel


2016-03-09 23:55 GMT+01:00 Robby Findler <ro...@eecs.northwestern.edu>:

> Scribble has a big table mapping unicode to latex commands. Maybe it
> needs another entry?
>
> Robby
>
>
> On Wed, Mar 9, 2016 at 4:07 PM, David Van Horn <dvanh...@cs.umd.edu>
> wrote:
> > Yes, the problem then is the code font doesn't support that character
> > so it doesn't show up.
> >
> > David
> >
> >
> > On Wed, Mar 9, 2016 at 5:05 PM, Leif Andersen <l...@leifandersen.net>
> wrote:
> >> Have you tried running the outputted tex file in xetex rather than
> pdflatex?
> >>
> >> ~Leif Andersen
> >>
> >>
> >> On Wed, Mar 9, 2016 at 5:03 PM, David Van Horn <dvanh...@cs.umd.edu>
> wrote:
> >>> I have some source code I'm trying to typeset in a racketblock that
> >>> uses subscript characters like ₀.  This breaks when it gets to latex.
> >>> Is there some workaround to generate latex friendly output?
> >>>
> >>> Thanks,
> >>> David
> >>>
> >>> --
> >>> 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.
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Pattern Matching in Macros | Meaning of dot

2016-03-13 Thread Jens Axel Søgaard
The cons cell constructed by (cons 1 2)
is normally printed as (1 . 2).

The list created by (list 1 2 3) could also be created
as (cons 1 (cons 2 (cons 3 '(. It could be printed as
(1 . (2 . (3 . (.

Normally lists are simply printed as (1 2 3) though.
Notice that (1 . (list 2 3)) is the same list since (cons 1 (list 2 3))
is the same as (list 1 2 3).

In a round about way we have arrived at the pattern (name . args).

Suppose we have a syntax object representing a list (plus 1 2 3)
which could be written as (plus . (1 2 3)).
If we match this against (name . args) we see that name matches plus
and that args now matches (1 2 3).

To practise the dot notation you can use the repl (since the reader
understands dot notation.

> ( 1 . (2 3 4))
...


/Jens Axel






2016-03-13 16:05 GMT+01:00 Pedro Caldeira <pedro.calde...@bluewin.ch>:

> Hello everyone,
>
> Since I've discovered the concept of metaprogramming I've been quite
> interested in Racket and its syntax extension capabilities.
>
> While searching for a memoization syntax extension I found a macro whose
> pattern extension remained unclear.
>
> (define-syntax define/memoized
>   (syntax-rules ()
> ((_ (name . args) . body)
>  (define name (memoize (lambda args . body))
>
> With the memoization function being defined as such:
>
> (define (memoize f)
>   (local ([define table (make-hash)])
> (lambda args
>   (dict-ref! table args (lambda () (apply f args))
>
> What does the '.' mean in '(name . args)' and '. body'?
>
> In a call like (define/memoized (foo x y z) (displayln "bar"))) I would
> imagine that name would be matched to foo; (x y z) to args and body to
> (display ln "bar") but why do we use the '. body' in the lambda expression
> at the end?
>
> Thank you for your attention.
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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: Pattern Matching in Macros | Meaning of dot

2016-03-13 Thread Jens Axel Søgaard
If we use

(define-syntax define/memoized
  (syntax-rules ()
((_ (name . args) . body)
 (define name (memoize (lambda args  body))

and body is bound to((displayln x) (displayln y) (displayz))
then

(lambda args  body)

will become

(lambda  ((displayln x) (displayln y) (displayz)))

And when this function is called you will get an error since

((displayln x) ...)

means apply the result of (displayln x) to (displayln y) (displayln x).

/Jens Axel




2016-03-13 19:32 GMT+01:00 Pedro Caldeira <pedro.calde...@bluewin.ch>:

> Sorry I've messed up my reply, here's the actual reply
>
> >Imagine (_ (foo x y z) (displayln x) (displayln y) (displayln z)) as the
> actual syntax. The .body will be bound to the sequence of three diaplaylns
> and this sequence will become the body of the lambda in the expansion.
> So in this case body will be bound to the list ((displayln x) (displayln
> y) (displayz)) right?
>
> So why do we use the '.' in the lambda declaration, couldn't we just write:
> (define-syntax define/memoized
>   (syntax-rules ()
> ((_ (name . args) . body)
>  (define name (memoize (lambda args  body))
> In Scala the head and tail of a list can be matched in the following way:
> x :: xs with x being the head and xs the tail, is the dot notation similar
> in purpose? Is the expression (x . xs) in Racket used to match x with the
> head of the S-expression and xs with the rest of the S-expression?
>
> >(define-syntax define/memoized
> >  (syntax-rules ()
>
> >((_ (name arg ...) form ... expr)
> > (define name (memoize (lambda (arg ...) form ... expr))
> I see thank you for the different format, the notation with the tree dots
> is more intuitive. As a side note in the racket reference:
> https://docs.racket-lang.org/reference/stx-patterns.html is the pattern
> with the three dots described by (pattern ...) or by (pattern ellipsis)?
>
> @Jens Alex
> Thank you for the clarification, I think it might confirm what I wrote
> above (I was replying while you answered)
>
> Again, thank you all 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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: Re: [racket-users] Pattern Matching in Macros | Meaning of dot

2016-03-14 Thread Jens Axel Søgaard
Yes, lambda expression have an implicit begin in the body.

> (begin . (1 2 3))
3

> (begin (1 2 3))
application: not a procedure;
expected a procedure that can be applied to arguments
given: 1
 arguments...:

Here (begin . (1 2 3)) is the same as (begin 1 2 3).

The docs for lambda are here:

http://docs.racket-lang.org/reference/lambda.html?q=lambda#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._lambda%29%29

Note the body ...+ which means 1 or more bodies are allowed.

/Jens Axel







2016-03-14 18:37 GMT+01:00 Pedro Caldeira <pedro.calde...@bluewin.ch>:

> Does that mean that lambda expressions have an implicit (begin …) block
> in them?
>
> (begin ((displayln 1) (displayln 2) (displayln 3))) leads to an error
>
> (begin . ((displayln 1) (displayln 2) (displayln 3))) displays to 1 2 3
>
> Thank you for the detailed explanation I think I get it now.
>
> On 13 Mar 2016, at 19:48, Jens Axel Søgaard <jensa...@soegaard.net> wrote:
>
> If we use
>
> (define-syntax define/memoized
>   (syntax-rules ()
> ((_ (name . args) . body)
>  (define name (memoize (lambda args  body))
>
> and body is bound to((displayln x) (displayln y) (displayz))
> then
>
> (lambda args  body)
>
> will become
>
> (lambda  ((displayln x) (displayln y) (displayz)))
>
> And when this function is called you will get an error since
>
> ((displayln x) ...)
>
> means apply the result of (displayln x) to (displayln y) (displayln x).
>
> /Jens Axel
>
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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: Racket -> HTML+JavaScript using Urlang and Ractive

2016-03-19 Thread Jens Axel Søgaard
2016-03-16 22:18 GMT+01:00 Greg Trzeciak :

>
> Thanks Dan, seems to be exactly what I need (especially the combination
> with ractive.js! BTW you couldn't find js framework with name more fitting
> to work with racket ;)
> I am only curious what racket subset does urlang include or rather what
> won't work in urlang.


Hi Greg,

Think of Urlang as JavaScript with s-expression syntax.
The core urlang language includes constructs that mirror JavaScript almost
one-to-one.
So Urlang is not "Racket to JavaScript compiler".

There are few miniscule differences:
-   functions support optional arguments
-  The = operator generates === in JavaScript
-  if will only count the false  value as false (zero is not considered
to be true)

That said: Urlang does support macros, which means you can write
constructs that expand into core Urlang.

In urlang/for you will find a Racket-ish for constructs.
That is  for, for*, for/sum, for*/sum etc

https://github.com/soegaard/urlang/blob/master/urlang/for.rkt

In urlang/extra you will find some often used macros:

These constructs can be used as expressions:

; (begin0 expr statement ...)
; (when   test statement ... expr)
; (unless test statement ... expr)

; (cond [test statement ... expr] ...)
; (case val-expr clause ...)
;  where clause is  [(datum ...) statement ... expr]
;   or  [elsestatement ... expr]
; (letrec ([id val-expr] ...) statement ... expr)
; (let*   ([id val-expr] ...) statement ... expr)

;; These constructs can be used as statements:
; (swhen   test statement ...)
; (sunless test statement ...)
; (scond  [test statement ...] ...)

https://github.com/soegaard/urlang/blob/master/urlang/extra.rkt

We are working on making some more examples.

/Jens Axel

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


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

2016-04-05 Thread Jens Axel Søgaard
Perhaps Ray Racine's library?

https://github.com/RayRacine/munger/tree/master

Look at the munger/frame/frame.rkt

2016-04-05 21:04 GMT+02:00 'John Clements' via Racket Users <
racket-users@googlegroups.com>:

> I’ve been dabbling in data analysis in Racket for the last few months, and
> one thing that’s become immediately obvious is that we don’t have a nice
> notion of a “table”.
>
> I believe that the natural notion of a “table” here is more or less the
> same in R and in databases: A table consists of a set of column names, and
> a set of tuples with values for each of those columns.
>
> After building my own and messing with it for a while, I basically rewrote
> it as a front-end to sqlite3. So, for instance, you can create a table by
> writing
>
> (make-table
>   ‘(student qtr score)
>   ‘((“janice” 2152 32.4) (“franklin” 2164 29.9) (“zongthar” 2174 .9))
>
> … and then query it in a variety of useful ways.
>
> 1) has anyone else already built and released this, and I just couldn’t
> find it in pkgs?
>
> 2) Is it worth building the functional-skinned interface, or is it easier
> just to write lots of SQL code?
>
> John
>
>
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Racket change button% coordinates(X and Y axis)

2016-04-10 Thread Jens Axel Søgaard
2016-04-10 17:18 GMT+02:00 Theodor Berza :

> I have a button in a frame and when I change the vert-margin and
> horiz-margin in the code the button doesn't change it's location but rather
> the frame gets smaller or larger.
>
...

> Someone suggested me to create a vertical-panel that has 2 rows of
> horizontal panels, the height of the first horizontal panel determining the
> Y-coordinates and the width of the smaller panel in the second horizontal
> panel determining the X-coordinates of the button.
>

That'd be me. I have added a code example:

http://stackoverflow.com/a/36519013/23567

The purpose of this project is to make a GUI Builder where the user drags
> buttons on a frame and the position of the cursor changes in the code the X
> and Y axis. This would be impossible with building 3 panels for each button
> in a frame that has for example 20 buttons.
>

In that case I see why your are not fond of the solution above.


> Is there a way to add the X and Y coordinates in code without doing hacks?
>

There is a pasteboard% that can be used to place snips at arbitrary
coordinates.
The gui components aren't snips though. That requires that you define your
own snips.
You will need to make a snip type for each gui component.
That is a snip-pane%, snip-panel% etc.

/Jens Axel

-- 
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] Trouble with displaying value-turtles

2016-03-19 Thread Jens Axel Søgaard
I ran your program and was, too, a bit confused at first.
But ... turns out it is simple.
Run the program in DrRacket.
Switch to the repl.
Then scroll up!
The "windows" are displayed as pictures in the repl,
but they are so big, that you can't see them at first.

/Jens Axel




2016-03-19 22:47 GMT+01:00 <nikof...@gmail.com>:

> Hello,
>
> I am beginning a project in which I want to use Racket's turtle
> functionality to implement the examples and exercises from the book Turtle
> Geometry.
>
> In doing so, there is of course the choice between the traditional turtles
> (graphics/turtles) and the value turtles (graphics/value-turtles).
>
> I am playing around with the two libraries to pick a direction. The
> implication is that the value-turtules is more functional in nature and
> thus the ideal, long-term way to go. However, I am unable to get a turtle
> window to display.
>
> For example, the following code does nothing and returns no errors:
> #lang racket
> (require graphics/value-turtles)
> (require graphics/value-turtles-examples)
> (define twindow (turtles 500 500))
> (neato twindow)
> twindow
>
> For the traditional turtles, the following code works just fine:
> #lang racket
> (require graphics/turtles)
> (require graphics/turtle-examples)
> (turtles #t)
> (neato)
>
> What am I doing wrong with the value-turtles? It's not clear how to
> actually display the turtle window/drawing.
>
> This isn't related to this issue is it?
> https://groups.google.com/forum/#!searchin/racket-dev/turtles/racket-dev/qv840Wtwu5E/vC08lyZjAWQJ
>
> Thanks!
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Racket -> HTML+JavaScript using Urlang and Ractive

2016-03-23 Thread Jens Axel Søgaard
The goal for the core Urlang language is to be almost 1-to-1 with
JavaScript.
Therefore I haven't used any JavaScript libraries. As Dan's examples
shows (see urlang/urlang-examples) it is straightforward to use existing
JavaScript libraries.

There are a few predefined macros that one can optionally use:
cond, case, for etc which are Urlang macros that expand into
core Urlang (think JavaScript) constructs. The ability to extend JavaScript
with a sane macro system was what I wanted to achieve.

The source code for Space Invaders is a port of an HtDP-style program.
The attempt was to match the original HtDP-style and I think it turned out
pretty well.

It contains an ad-hoc implementation of structs in Urlang (JavaScript), so
when
you want to access the x-coordinate of a player p, you will see (player-x p)
in the code. If the program was written from scratch I would have used p.x
which is the standard JavaScript notation of access x in an object (or
array) p.

If anyone wonders why I chose (var [x 42] [y 43]) rather than adding
an internal define to Urlang - it is due to the scoping rules. The
var-form follows the scoping rules of JavaScript - which means it
has block-scope.

If normal local scope is needed one can use the the let-macro (or letrec*)
from urlang/extra.

/Jens Axel




2016-03-23 12:42 GMT+01:00 Daniel Prager <daniel.a.pra...@gmail.com>:

> On Sun, Mar 20, 2016 at 9:44 AM, Matthew Butterick <m...@mbtype.com> wrote:
>
>> When you put it that way, subjectively it still sounds good. I'd use it.
>> But objectively I can't foresee that it would be a wise investment of
>> anyone's Racket time. Let's face it: any web framework is lucky to live 5
>> yrs before developers tire of it and move onto the next thing, or browser
>> changes make it obsolete.
>>
>
> The shifting of the underlying platform is inevitable -- perhaps
> eventually it will settle down -- and empirically your point about
> web-frameworks checks out, suggesting that it would be unwise to bake in
> reliance on any particular framework.
>
> That said, I reckon that there are gains to be made via making use of
> existing JavaScript frameworks and libraries.
>
> OTOH: Here's a new example from Jens that has zero dependencies on
> external JS - a simple Space Invaders game in Urlang:
> http://soegaard.github.io/urlang/space-invaders.html
>
> Dan
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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: Racket -> HTML+JavaScript using Urlang and Ractive

2016-03-19 Thread Jens Axel Søgaard
2016-03-16 22:50 GMT+01:00 Greg Trzeciak :

> "Urlang is a Racket flavoured S-expression syntax for Javascript"
>

Can I steal that for a tag-line?


> Thank you for your explanation - still seems like a good fit for one of my
> projects (as I needed something more lightweight than Whalesong) so I will
> try it out shortly.
>

Sounds great. Don't hesitate to send feedback.

/Jens Axel

-- 
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: Racket 6.4 very slow

2016-03-02 Thread Jens Axel Søgaard
2016-03-02 19:26 GMT+01:00 vkelmenson via Racket Users <
racket-users@googlegroups.com>:


> Also: When I am typing in the interactions pane of 6.4 there is often a
> 1-2 second delay before my
> keystrokes show up.
>
>
It sounds as if something went wrong during the installation on Racket.
How did you install it?
If you compiled it yourself, you most likely forgot to run raco setup.
The downloads from download.racket-lang.org contains precompiled files.

/Jens Axel

-- 
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] function minimization

2016-03-02 Thread Jens Axel Søgaard
The root finder is the right tool.

Add this below your program:

(require math/flonum)

(define (df/dx x)
  (define f badness)
  (define h 0.0001)
  (define d (/ (- (f (+ x h)) (f (- x h)))
   (* 2.0 h)))
  (if (zero? d)
  +inf.0
  d))

(plot (list (function df/dx)
(function (λ (x) 0.0)))
  #:width 1300
  #:x-min 1
  #:x-max 120
  #:y-min -5e-8)


(flbracketed-root df/dx 5.0e5  6e5)
(flbracketed-root df/dx 7.5e5 10e5)


The results are:
514285.7058330256
817605.5857361854

I don't know what the "proper" value of h ought to be
and how much it affects the results. (A few experiments
show that the integer part ought to trustworthy).

Maybe you can combine the approach with golden section
search to hone in on a more precise value?

/Jens Axel






2016-03-02 18:36 GMT+01:00 'John Clements' via Racket Users <
racket-users@googlegroups.com>:

> I’m trying to minimize a function. It’s a continuous function made up of
> piecewise well-behaved functions of the form (k_0 / x) +( k_1 / x^2). It’s
> not hard to solve these analytically, but since they’re piecewise functions
> each with different coefficients, I figured I’d ask first: does the math
> package have a built-in function minimization operator? I looked around a
> bit and found the root-finder, but not a minimizer.
>
> Well, what the heck; racket is compact, I might as well include some
> sample code and a picture.
>
> Any help appreciated!
>
>
> #lang racket
>
> (require math/statistics)
>
> ;; this file tries to determine the "best-fit" l for each user.
>
> ;; the model in this case is a one-parameter model, defining this
> ;; simplified learning function:
>
> ;; f(t) = (1 - t/l) when 0 < t < l
> ;; f(t) = 0 when t >= l
>
> (require plot)
>
> (define example-sequence
>   '(#(0 1)
> #(40 2/9)
> #(70 3/9)
> #(80 0)
> #(100 0)))
>
> (plot (list (points example-sequence)
> (lines example-sequence))
>   #:x-max 120
>   #:width 1300)
>
> ;; this fitness function measures the mean squared distance
> ;; from the datapoints to Model_l.
> ;; I want to find the value of l that minimizes this function
> (define (badness l)
>   (mean
>(for/list ([pt (in-list example-sequence)])
>  (match-define (vector t e) pt)
>  (expt (cond [(< t l) (- e (- 1 (/ t l)))]
>  [else e])
>2
>
> (plot (function badness)
>   #:width 1300
>   #:x-min 1
>   #:x-max 120
>   #:y-min 0)
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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: Racket 6.4 very slow

2016-03-02 Thread Jens Axel Søgaard
Could it be that the OS X 10.8.5 has something to do with it?
Does anybody else have an 10.8 (Mountain Lion) installation?

/Jens Axel


2016-03-02 20:39 GMT+01:00 vkelmenson via Racket Users <
racket-users@googlegroups.com>:

> On Tuesday, March 1, 2016 at 10:51:58 PM UTC-5, vkelm...@aol.com wrote:
> > I recently downloaded Racket version 6.4. I have previously been using
> version 6.1. It is much slower than version 6.1. Several short functions
> run approx 20 times slower on 6.4 than 6.1. These were run at the same time
> on the sam matine in succession.
> > I am using Mac osX version 10.8.5
> >  Has anyone else noticed this?
>
> Obviously something is wrong with my setup. I uninstalled version 6.4 from
> my computer and reinstalled the dmg from the download site. It is still the
> same. I am not going to have access to my desktop for about 10 days. I will
> see what happens with a laptop.
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] DrR: meta-q just worked!

2016-03-05 Thread Jens Axel Søgaard
Is there a way to set the paragraph width to 80 (it seems to be set to 60)?

/Jens Axel


2016-03-04 21:06 GMT+01:00 Robby Findler <ro...@eecs.northwestern.edu>:

> Lei Wang actually implemented it. I gave him some advice about it, but
> it was his work. I'm very happy he did it too!
>
> https://github.com/LeiWangHoward
>
> Robby
>
>
> On Fri, Mar 4, 2016 at 10:31 AM, Matthias Felleisen
> <matth...@ccs.neu.edu> wrote:
> >
> > Thank you Robby. He added this a while back because it was my primary
> complaint about scribble in dr.
> >
> >
> > On Mar 4, 2016, at 10:40 AM, "'John Clements' via Racket Users" <
> racket-users@googlegroups.com> wrote:
> >
> >> I was editing scribble code, and by reflex, typed meta-q to reflow the
> >> text. I was somewhat astonished when it worked. Is this a recent change?
> >>
> >> I think I take DrRacket for granted way too often. Many, many thanks for
> >> an awesome IDE.
> >>
> >> John
> >>
> >>
> >>
> >> --
> >> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] r6rs use

2016-04-02 Thread Jens Axel Søgaard
I am no R6RS expert (so I might have missed something),
but I believe there are two issues:

- there is no repl specified in r6rs (only top level programs)
  (implementation can of course provide a repl, but they don't have to)

- the function  sort  is supposed to be unbound
  (the sorting functions in r6rs are called list-sort, vector-sort,
and, vector-sort!)

Since your program works in the other implementations, I am guessing that
they offer  sort   as an alias for list-sort.

/Jens Axel



2016-04-02 8:29 GMT+02:00 Damien Mattei <damien.mat...@gmail.com>:

> Hi,
>
> i have a code that works well in #lang racket and also with other scheme
> compilers with minor changes,Bigloo,MIT scheme, but it does not work with
> #!r6rs
>  i do not know why,here it is (some extract):
>
> #!r6rs
> (import (rnrs))
>
>
> ...
>
> ;; sort operands in a logic expression
> ;; (sort-arguments-in-operation '(or Ci a b)) -> '(or a b Ci)
> ;; (sort-arguments-in-operation '(or Ci (not a) b)) -> '(or (not a) b Ci)
> ;; (sort-arguments-in-operation '(or Ci (not a) b (or c d))) -> '(or (not
> a) b (or c d) Ci)
> (define (sort-arguments-in-operation expr)
>   (if (isOR-AND? expr)
>   (let* ((args-list (args expr)) ;;'(or Ci a b) -> '(Ci a b)
>  (expression->string (lambda (expr2) (cond ((symbol? expr2)
> (symbol->string expr2)) ;; #t -> "T", #f -> "F"
>((boolean? expr2)
> (if expr2 "T" "F"))
>(else (error
> "sort-arguments-in-operation: do not know how to handle this expression"
> expr2)
>  (lower-litteral-symbol (lambda (s) (string-downcase
> (expression->string (get-first-litteral s) ;; 'Ci -> "ci", '(not A) ->
> "a"
>  (expression x) (lower-litteral-symbol y
>  ;;(sorted-args (sort args-list #:key lower-litteral-symbol
> string '(a b Ci)
>  (sorted-args (sort args-list expression  (oper (operator expr))) ;; define operator : (or Ci a b) -> or
> (cons oper sorted-args))
>   expr)) ;; we have not a binary operator but a litteral or negation
> of litteral
>
>
>
> ...
>
>
> Bienvenue dans DrRacket, version 6.1.1 [3m].
> Langage: r6rs [personnalisé]; memory limit: 256 MB.
> . sort: unbound identifier in module in: sort
>
> Interactions disabled: r6rs does not support a REPL (no #%top-interaction)
>
> sort seems unbound, also eval !!! and i suppose a lot more making the
> basis of scheme language
> problem is not with the code,i know it works but
> question is "what is the good way to use r6rs compatibility with DrRacket?"
>
> regards,
>
> damien
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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 Jens Axel Søgaard
2016-04-04 21:34 GMT+02:00 rom cgb <romainbeck...@gmail.com>:

> Hi,
>
> Trying to use eof in a case expression but it doesn't work.
>
> For example
>
> (define (test x)
>   (case x
> [(eof) eof]
> [else  "else"]))
>
>
> (test eof) will then evaluate to "else" despite (equal? eof eof)
> evaluating to #t.
>
> Why ?


The (eof) clause in case is a list of datums. That means case
will taste for the symbol eof and not the end of file object.

(case 'eof
  [(eof) 42])   ; 42

(case eof
  [(eof) 42]
  [else  #f])  ; #f

Instead use cond
  (cond
[(eof-object? x) ...]
[else  #f])

/Jens Axel





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



-- 
-- 
Jens Axel Søgaard

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

2016-04-04 Thread Jens Axel Søgaard
Btw - if you like to use case, you could try the old evcase instead:

http://docs.racket-lang.org/mzlib/mzlib_etc.html?q=evcase#%28form._%28%28lib._mzlib%2Fetc..rkt%29._evcase%29%29

2016-04-04 22:36 GMT+02:00 rom cgb <romainbeck...@gmail.com>:

> I see, that's why it also does work with string constants. Thanks.
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Macro calling macro question

2016-05-20 Thread Jens Axel Søgaard
The macro application (foo 3) expands into

   #'(begin
(_foo n0)
(foo n ...))

The expansion of (_foo n0) then defines foo3, but
the scope will only include the piece of code above.

To make definitions made by sub-macros available
at the original macro application site, you can use
syntax-local-introduce:

(define-syntax (foo stx)
  (syntax-case stx ()
[(_)  #'(begin)]
[(_ n0 n ...) (syntax-local-introduce
#'(begin
(_foo n0)
(foo n ...)))]))

Note that I changed the pattern variable to _ in order not to
show shadow the binding of foo.

This might not be strictly necessary here, but if you do
run into such a case, it will be hard to spot the error.

/Jens Axel










2016-05-20 23:36 GMT+02:00 Kevin Forchione <lyss...@gmail.com>:

> Hi guys,
> I’ve been interested in having a macro build a series of defines. So I
> decided to start small, trying to get to a macro that would do something
> like the following to begin with:
>
> >(foo 3)
> (define foo1 1)
> (define foo2 2)
> (define foo3 3)
>
> I start with a macro that appears to do a single define:
>
> (require (for-syntax racket/syntax))
>
> (define-syntax (_foo stx)
>   (syntax-case stx ()
> [(_ n) (with-syntax ([id (format-id stx "foo~a" (syntax-e #'n))])
>  #'(define id n))]))
>
>
> And this appears to work for (_foo 3) for instance.
>
> Then I create a macro that calls this macro:
>
> (define-syntax (foo stx)
>   (syntax-case stx ()
> [(foo n0) #'(_foo n0)]
> [(foo n0 n ...) #'(begin
>   (_foo n0)
>   (foo n ...))]))
>
> thinking that I could do something like (foo 1 2 3) as an intermediary
> step.  So I test it with (foo 3) for instance, expecting it to define foo3
> and the macro debugger tells me that it’s created (define foo3 3), but that
> foo3 is bound as foo3.0, which is a mystery to me as I thought building the
> id using with-syntax and format-id  would have sorted the binding for this.
>
> Looks like I’m at a learning moment…. any explanation why executing (_foo
> 3) at the real works and (foo 3) does not?
>
> Thanks!
> -Kevin
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Problem with macro which implements selectors for mutable pairs

2016-05-12 Thread Jens Axel Søgaard
mcons (mcons 1 2) (mcons (mcons 3 4) '()
  (list (mcaar a)
(mcdar a)
(mcaadr a)
(mcdadr a






2016-05-12 10:45 GMT+02:00 Joan Martin <joanmar1...@gmail.com>:

> Hi,
> I'm trying to program a macro which defines different selectors for
> mutable pairs.
> I know in Racket it's possible to use only mcar and mcdr, but mcdar etc.
> could be useful for me.
>
> I would like to use macro this way:
>
> (with-mcxrs
>   (let ((a (mcons (mcons 1 2) (mcons (mcons 3 4) '()
>(list (mcaar a)
>  (mcdar a)
>  (mcaadr a)
>  (mcdadr a
>
> Mcxrs will be defined in macro's body and then whole expresion would be
> evaluated - now with bindings in macro's environment so no error should
> appear.
> I think procedure seek and macro defines3 are ok (when using separately
> they work fine) but in a macro "with-mcxrs" an error appears: mcaar
> undefined.
> Where's the problem? I can't figure it out. I would be glad if anyone
> could give me some advice.
>
> And could "defines3" be out of macro "with-mcxrs"? Or should it be inside
> - like in my code?
> Thanks a lot.
>
> Code:
>  first I go though whole body and I store found mcxrs in list, which is
> called "selectors" in let loop. And then call another macro "defines3"
> which should return procedure - for example: (lambda (pair) (mcar (mcdr
> (mcar pair. And this procedure should be defined as a value of
> particular mcaar or mcdar etc.
>
> (define-macro with-mcxrs
>   (lambda body
>
> `(define-macro defines3
>   (lambda (chars)
> (let ((loop (gensym)))
>   `(lambda (pair)
>  (let ,loop ((chsez ,chars))
>(if (null? chsez)
>pair
>(if (equal? (car chsez) #\a)
>(mcar (,loop (cdr chsez)))
>(mcdr (,loop (cdr chsez ))
>
> (define seek2
>   (let ((pom '() ))
> (lambda (l)
>   (cond ((null? l) pom )
> ((list? (car l)) (begin(seek2 (car l))
>(seek2 (cdr l))) )
> (else
>  (if (not (symbol? (car l)))
>  (seek2 (cdr l))
>  (let* ((test (symbol->string(car l)))
> (len (string-length test)))
>(if (> len 4)
>(if (or (equal? (substring test 0 3) "mca")
>(equal? (substring test 0 3) "mcd"))
>(begin
>  (set! pom (cons (car l) pom) )
>  (seek2 (cdr l)))
>(seek2 (cdr l)))
>(seek2 (cdr l)) 
>
> (let ((loop (gensym)))
>   `(let ,loop ((selectors (,seek2 (quote ,@body)) )) ;;list of
> selectors
> (cond ((null? selectors) (,@body))
>   (else
> (define (car selectors)
>  (defines3 (string->list
> (substring (car l) 2
>     (- (string-length (car l))1)) )))
>(,loop (cdr selectors))) )))  ))
>
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Modernizing scribble/html

2016-04-15 Thread Jens Axel Søgaard
Hi All,

The library scribble/html paired with at-expressions provide a really nice
way to write html:

  @html[@head[@title{This is a title}]
  @body[@h1{This is a header}
   @p{This is a paragraph with text}]]

The library represents html as structures. Each html element type has its
own Racket structure. The library is based on the elments available
in xhtml1

http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd

Since then new elements have appeared ( svg for one ).
On an ad hoc basis I have added elements, to urlang/html but am realizing
a systematic approach is better.

The simple solution is to take the elements from

https://www.w3.org/TR/html/index.html#elements-1

and add them to scribble/html.

Is the simple solution also the right solution?

-- 
Jens Axel Søgaard

-- 
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] Does `read-words/line' preserve last newline information?

2016-04-16 Thread Jens Axel Søgaard
2016-04-16 6:39 GMT+02:00 Quico Jurado :

> Hello, I posted this question in SO, but hoping to get more answers here.
>

Link to the SO posting:

http://stackoverflow.com/questions/36611808/racket-2htdp-does-read-words-line-preserve-last-newline-information

/Jens Axel

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