[racket-users] lovely illustration of the importance of teaching languages...

2017-04-26 Thread 'John Clements' via Racket Users
This nightmarish but organic example produced by a student actually works 
correctly, and is a beautiful example of why we need teaching languages (or a 
type system that enforces boolean inputs to ‘or’):

https://www.brinckerhoff.org/blog/

Note that while the actual student code is in python, it’s 100% 
transliteratable to Racket, and you could produce exactly the same horrible 
result…if you weren’t using a teaching language.

Just thought I’d share.

Sweet dreams!

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.


[racket-users] Re: How to improve compile times?

2017-04-26 Thread Alex Harsanyi
I would also like to know more about this topic.  I have never done any 
rigorous tests, however for my application which takes about 7 seconds to load, 
I have observed the following:

* there is no big startup difference between running the application as "racket 
run.rkt" (which loads the already compiled .zo files from disk) and running an 
executable (which has the .zo files bundled in the executable, so presumably 
already in memory).
* while the application creates a GUI frame and a complex set of widgets at 
startup, that part of code runs very fast, so most of those 7 seconds are spent 
loading modules
* my application does not use macros (except what is already there in racket 
libraries).

In the end I just did a "lazy-require" for the main application and just added 
a splash screen (which still takes 1-2 seconds to show up) so the user has 
something to admire while the application loads up.

Best Regards,
Alex.


On Thursday, April 27, 2017 at 6:04:15 AM UTC+8, Dupéron Georges wrote:
> Hi all!
> 
> Some of my libraries take a while to load: just adding a (require mylib) to 
> an empty #lang racket/base file bumps the compile time from 0.5s to 1.5s, 
> even if no bindings from the library are used. After experimenting a bit, it 
> seems that the overhead is mainly due to other modules which are transitively 
> required (typed/racket, syntax/parse, …).
> 
> Assuming that all the files except the main one are already byte-compiled 
> with raco make, what are the factors which affect compile times when a 
> library is (possibly transitively) required? Note that we're talking about 
> milliseconds here, but when a lot of modules are required, these can add up.
> 
> 1. Number of bindings directly provided?
> 2. Number of bindings provided by transitively-required modules (including 
> those which are not re-provided, and are not in the main file's namespace)
> 3. Number of files which are transitively required?
> 4. Size of the fully expanded code (or size of the bytecode)?
> 5. Compile-time operations, e.g. within a begin-for-syntax in a 
> (transitively-)required module?
> 6. When a module is required at several meta-levels, does it affect the 
> compile time significantly, or is it roughly the same cost than requiring it 
> only once?
> 7. Something else?
> 
> Point 5 seems to matter, as compiling a.rkt still prints "Hello" even if 
> b.rkt is already compiled:
> 
> a.rkt:
> #lang racket/base
> (require "b.rkt")
> 
> b.rkt:
> #lang racket/base
> (require (for-syntax racket/base))
> (begin-for-syntax (displayln "Hello"))
> 
> However, I'm not sure what operations can cause compile-time code to be run 
> in this situation. My (possibly incorrect) understanding is that macros are 
> executed only once (when expanding the code), but the code to the 
> right-hand-side of a (define-syntax foo costly-operation), and the code 
> within a (begin-for-syntax …) will both be run each time the module is 
> required.
> 
> What I would like is to learn a few "good practices" and gotchas concerning 
> compile-time performance.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Speeding up graphics / moving away from 2htdp/image

2017-04-26 Thread Daniel Prager
On Thu, Apr 27, 2017 at 12:34 PM, Vishesh Yadav  wrote:

>
>> BTW: I'm interested in porting to RacketScript. How does the performance
>> of the image library equivalent compare with regular Racket?
>>
>>
> It is slower than regular Racket. I did not spend much time comparing it
> with Racket, and there is definitively scope for improvement. Let us know
> how porting goes.
>

Thanks: it's on my list.

I may try to do some reduced-case benchmarks for a few approaches in
Racket, and for RacketScript.

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.


Re: [racket-users] Speeding up graphics / moving away from 2htdp/image

2017-04-26 Thread Vishesh Yadav
>
>
> BTW: I'm interested in porting to RacketScript. How does the performance
> of the image library equivalent compare with regular Racket?
>
>
It is slower than regular Racket. I did not spend much time comparing it
with Racket, and there is definitively scope for improvement. Let us know
how porting goes.

--Vishesh


> Dan
>
> On 26 Apr. 2017 15:30, "Vishesh Yadav"  wrote:
>
> Are you repeatedly generating image for an animation inside an event loop?
>
> Depending on the kind of program `freeze` from 2htdp/image may help if you
> haven't tried already. For example this[1] program renders faster with
> freeze both in RacketScript and 2htdp/image.
>
> [1] http://rapture.twistedplane.com:8080/#example/default
>
> --Vishesh
>
> On Tue, Apr 25, 2017 at 9:09 PM, Daniel Prager 
> wrote:
>
>> Much as I enjoy making images using 2htdp/image it does get a tad slow as
>> complexity increases.
>>
>> I currently have a program in which I generate images in 2htdp/image and
>> translate them into bitmap%s per racket/gui and render on canvas%'s via a
>> dc.
>>
>> Speed has become sluggish and I'm going to need to move away from
>> 2htdp/image to address this.
>>
>> A typical image is built up out of lots of above, beside, overlay,
>> square, and triangle calls.
>>
>> Does anyone have a "clever" way to do this programatically (rather than a
>> manual re-write with lots of absolute calculations replacing heights and
>> widths)?
>>
>> Many 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.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Lexical context for all-defined-out

2017-04-26 Thread Philip McGrath
Thanks, that does the trick!

-Philip

On Wed, Apr 26, 2017 at 6:27 PM, Matthew Flatt  wrote:

> The `all-defined-out` macro supports a trick that several non-hygienic
> macros use: it uses the scopes on the parentheses around
> `all-defined-out` non-hygienically, instead of the scopes on the
> identifier.
>
> So, in place of
>
>  (datum->syntax stx '(all-defined-out)))
>
> you can use
>
>  (datum->syntax stx `(,#'all-defined-out)))
>
> and then you don't have to export `all-defined-out`.
>
> At Wed, 26 Apr 2017 18:01:00 -0500, Philip McGrath wrote:
> > I'm working on a #%module-begin variant that provides all module-level
> > bindings, and I'm having trouble finding the right way to give lexical
> > context to all-defined-out.
> >
> > The issue (IIUC) is that all-defined-out only exports identifiers "that
> > have the same lexical context as the (all-defined-out) form"; however, I
> > want to have #%module-begin introduce all-defined-out, but have it export
> > the identifiers defined by the programmer in the body of the module.
> >
> > Currently what I'm doing is essentially this:
> >
> > #lang racket
> >
> > (module lang racket
> >   (provide (except-out (all-from-out racket)
> >#%module-begin
> >provide
> >;all-defined-out ;can't omit this
> >)
> >(rename-out [providing-module-begin
> > #%module-begin]))
> >   (require (for-syntax syntax/parse))
> >   (define-syntax (providing-module-begin stx)
> > (syntax-parse stx
> >   [(_ body:expr ...)
> >#`(#%module-begin
> >   (provide #,(datum->syntax stx '(all-defined-out)))
> >   body ...)])))
> >
> > (module demo (submod ".." lang)
> >   (define something
> > "a value"))
> >
> > (require (submod "." demo))
> >
> > something
> >
> >
> > This almost works — the providing happens correctly — but it requires
> that
> > the lang module provide all-defined-out, which I don't actually want to
> be
> > otherwise available.
> >
> > Is there a way to give all-defined-out the lexical context I'm looking
> for?
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] Lexical context for all-defined-out

2017-04-26 Thread Matthew Flatt
The `all-defined-out` macro supports a trick that several non-hygienic
macros use: it uses the scopes on the parentheses around
`all-defined-out` non-hygienically, instead of the scopes on the
identifier.

So, in place of

 (datum->syntax stx '(all-defined-out)))

you can use

 (datum->syntax stx `(,#'all-defined-out)))

and then you don't have to export `all-defined-out`.

At Wed, 26 Apr 2017 18:01:00 -0500, Philip McGrath wrote:
> I'm working on a #%module-begin variant that provides all module-level
> bindings, and I'm having trouble finding the right way to give lexical
> context to all-defined-out.
> 
> The issue (IIUC) is that all-defined-out only exports identifiers "that
> have the same lexical context as the (all-defined-out) form"; however, I
> want to have #%module-begin introduce all-defined-out, but have it export
> the identifiers defined by the programmer in the body of the module.
> 
> Currently what I'm doing is essentially this:
> 
> #lang racket
> 
> (module lang racket
>   (provide (except-out (all-from-out racket)
>#%module-begin
>provide
>;all-defined-out ;can't omit this
>)
>(rename-out [providing-module-begin
> #%module-begin]))
>   (require (for-syntax syntax/parse))
>   (define-syntax (providing-module-begin stx)
> (syntax-parse stx
>   [(_ body:expr ...)
>#`(#%module-begin
>   (provide #,(datum->syntax stx '(all-defined-out)))
>   body ...)])))
> 
> (module demo (submod ".." lang)
>   (define something
> "a value"))
> 
> (require (submod "." demo))
> 
> something
> 
> 
> This almost works — the providing happens correctly — but it requires that
> the lang module provide all-defined-out, which I don't actually want to be
> otherwise available.
> 
> Is there a way to give all-defined-out the lexical context I'm looking for?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


[racket-users] Lexical context for all-defined-out

2017-04-26 Thread Philip McGrath
I'm working on a #%module-begin variant that provides all module-level
bindings, and I'm having trouble finding the right way to give lexical
context to all-defined-out.

The issue (IIUC) is that all-defined-out only exports identifiers "that
have the same lexical context as the (all-defined-out) form"; however, I
want to have #%module-begin introduce all-defined-out, but have it export
the identifiers defined by the programmer in the body of the module.

Currently what I'm doing is essentially this:

#lang racket

(module lang racket
  (provide (except-out (all-from-out racket)
   #%module-begin
   provide
   ;all-defined-out ;can't omit this
   )
   (rename-out [providing-module-begin
#%module-begin]))
  (require (for-syntax syntax/parse))
  (define-syntax (providing-module-begin stx)
(syntax-parse stx
  [(_ body:expr ...)
   #`(#%module-begin
  (provide #,(datum->syntax stx '(all-defined-out)))
  body ...)])))

(module demo (submod ".." lang)
  (define something
"a value"))

(require (submod "." demo))

something


This almost works — the providing happens correctly — but it requires that
the lang module provide all-defined-out, which I don't actually want to be
otherwise available.

Is there a way to give all-defined-out the lexical context I'm looking for?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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: #:grammar and #:contracts of scribble

2017-04-26 Thread Dupéron Georges
Hi,

This sounds like a nice enhancement.

You might want to request this at https://github.com/racket/scribble/issues .

Aside from the implementation difficulty (the code for defform and friends is 
large, handles many edge cases, and feels a bit like spaghetti code), one of 
the main concerns would be how this change would affect existing scribble 
documentation: if the alignment pushes text into the right margin when it was 
nicely fitting within the main content column, this might be a concern (I do 
not remember if the contracts have auto-wrap, if so this problem would not 
arise).

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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 improve compile times?

2017-04-26 Thread Dupéron Georges
Hi all!

Some of my libraries take a while to load: just adding a (require mylib) to an 
empty #lang racket/base file bumps the compile time from 0.5s to 1.5s, even if 
no bindings from the library are used. After experimenting a bit, it seems that 
the overhead is mainly due to other modules which are transitively required 
(typed/racket, syntax/parse, …).

Assuming that all the files except the main one are already byte-compiled with 
raco make, what are the factors which affect compile times when a library is 
(possibly transitively) required? Note that we're talking about milliseconds 
here, but when a lot of modules are required, these can add up.

1. Number of bindings directly provided?
2. Number of bindings provided by transitively-required modules (including 
those which are not re-provided, and are not in the main file's namespace)
3. Number of files which are transitively required?
4. Size of the fully expanded code (or size of the bytecode)?
5. Compile-time operations, e.g. within a begin-for-syntax in a 
(transitively-)required module?
6. When a module is required at several meta-levels, does it affect the compile 
time significantly, or is it roughly the same cost than requiring it only once?
7. Something else?

Point 5 seems to matter, as compiling a.rkt still prints "Hello" even if b.rkt 
is already compiled:

a.rkt:
#lang racket/base
(require "b.rkt")

b.rkt:
#lang racket/base
(require (for-syntax racket/base))
(begin-for-syntax (displayln "Hello"))

However, I'm not sure what operations can cause compile-time code to be run in 
this situation. My (possibly incorrect) understanding is that macros are 
executed only once (when expanding the code), but the code to the 
right-hand-side of a (define-syntax foo costly-operation), and the code within 
a (begin-for-syntax …) will both be run each time the module is required.

What I would like is to learn a few "good practices" and gotchas concerning 
compile-time performance.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Announcing Leibniz, a new language in the Racket universe

2017-04-26 Thread Dmitry Pavlov

Konrad,

Sorry I am a bit late to the party.
You may remember me from this topic: 
https://groups.google.com/forum/#!topic/racket-users/E6utg2Pv5hA
where I looked for a scientific language and a tool for code generation.

Leibniz seems to be very general. Is generation of (C or other) code from 
Leibniz one of the goals of the project?

Regarding the plans of future development of Leibniz, my humble opinion is that the 
"express algorithms" part is very important for, um, production use. Also, 
vectors and matrices. As an example, I would love to see (or be able to write) an 
equation for gravitational N-body problem (with arbitrary N) in Leibniz.

Best regards,

Dmitry

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


Re: [racket-users] Best way to write run-once-and-cache functions?

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

For non-nullary functions, you're looking for memoization / caching. There's a 
couple packages that do this, along with relate

- In the `sugar` package, the `sugar/cache` module gives you exactly this, in 
the form of a `define/caching` macro.
- The `tmemoize` package provides similar functionality for Typed Racket 
functions.
- The `with-cache` package gives you promise-like behavior for thunks that use 
an external storage system.
- The `remember` package gives you caching behavior for compile-time 
expressions that can be remembered across compilation runs.

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


Re: [racket-users] Best way to write run-once-and-cache functions?

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

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

#lang racket

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

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

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


Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-26 Thread David Storrs
On Wed, Apr 26, 2017 at 12:21 AM, Jon Zeppieri  wrote:

> I don't know that there's a right way, but if your functions are
> nullary, then promises are a decent fit:
>
> (define conf
>   (delay
> (with-input-from-file ...)))
>
> Then just (force conf) whenever you want the value.
>

Yeah, that works well.  Thanks!

Any thoughts on how to do it for non-nullary functions?

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

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


Re: [racket-users] Announcing Leibniz, a new language in the Racket universe

2017-04-26 Thread Konrad Hinsen
Alexander McLin  writes:

> One paper I have in mind is Hodgkin & Huxley's paper published in 1952
> where they first wrote down the equations describing the membrane
> voltage of the giant squid
> axon. 
> https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1392413/pdf/jphysiol01442-0106.pdf
>
> It'll be a good exercise for me to go through it and write a summary,
> transcribing the equations into the Leibniz notation.

After a quick look at the paper, I'd say this should be doable with
the current version of Leibniz, at least for the majority of equations.
One pitfall is the use of pseudo-equations, such as

 P = const. * ...

which looks like an equation but is really an affirmation of
proportionality.

- Konrad.

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


Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-26 Thread Matthias Felleisen

#lang racket

(define read-conf
  (let [(conf (delay (with-input-from-file “db.conf" (thunk (displayln "hello") 
(read)]
(thunk 
 (force conf

(read-conf)
(read-conf)

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


Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-26 Thread Tim Brown
On Wednesday, April 26, 2017 at 5:21:41 AM UTC+1, Jon Zeppieri wrote:
> (define conf
>   (delay
> (with-input-from-file ...)))
> 
> Then just (force conf) whenever you want the value.

I tend to call promises xxx-promise (e.g. conf-promise),
to remind me not to use them without force'ing them.

Does anyone else hold to a convention for naming promises?

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.


Re: [racket-users] Proper non-tail recursion?

2017-04-26 Thread Norman Gray


Greetings.

On 25 Apr 2017, at 23:51, 'John Clements' via Racket Users wrote:

In answer to your actual question, the most common name is “Tail 
Call Optimization,” which many people correctly object to because 
it’s not an optimization, it’s a change to the meaning of terms in 
the language


I've seen the phrase 'Tail Call Elimination' used, for precisely this 
reason, that it's not merely an optimisation.


While it's not as cute as Proper Implementation of Tail Call Handling, 
it's possibly more descriptive (saying 'proper' is rather begging the 
question), and close enough to the more widespread TCO to be 
intelligible.


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.


[racket-users] Re: Best way to write run-once-and-cache functions?

2017-04-26 Thread Jack Firth
A `define/delay` macro for this might be a good addition to `racket/promise`:

(define-simple-macro (define/delay id:id expr:expr)
  (begin (define p (delay expr)) (define (id) (force p

(define/delay conf
  (with-input-from-file "db.conf" read-json))

(conf) ;; forces promise

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Speeding up graphics / moving away from 2htdp/image

2017-04-26 Thread Daniel Prager
Thank-you all for the suggestions. I'll check them out and report back.

Vishesh: There is some repetition (not animation), but I removed all
caching to simplify and rework the interactive flow. It would be with
trying freeze in conjunction with updated caching.

BTW: I'm interested in porting to RacketScript. How does the performance of
the image library equivalent compare with regular Racket?

Dan

On 26 Apr. 2017 15:30, "Vishesh Yadav"  wrote:

Are you repeatedly generating image for an animation inside an event loop?

Depending on the kind of program `freeze` from 2htdp/image may help if you
haven't tried already. For example this[1] program renders faster with
freeze both in RacketScript and 2htdp/image.

[1] http://rapture.twistedplane.com:8080/#example/default

--Vishesh

On Tue, Apr 25, 2017 at 9:09 PM, Daniel Prager 
wrote:

> Much as I enjoy making images using 2htdp/image it does get a tad slow as
> complexity increases.
>
> I currently have a program in which I generate images in 2htdp/image and
> translate them into bitmap%s per racket/gui and render on canvas%'s via a
> dc.
>
> Speed has become sluggish and I'm going to need to move away from
> 2htdp/image to address this.
>
> A typical image is built up out of lots of above, beside, overlay, square,
> and triangle calls.
>
> Does anyone have a "clever" way to do this programatically (rather than a
> manual re-write with lots of absolute calculations replacing heights and
> widths)?
>
> Many 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.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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 make unit test for error "unbound identifier"?

2017-04-26 Thread Alexis King
You can use convert-syntax-error from syntax/macro-testing to convert
the syntax error to a runtime error, which can be caught by RackUnit:

http://docs.racket-lang.org/syntax/macro-testing.html#%28form._%28%28lib._syntax%2Fmacro-testing..rkt%29._convert-syntax-error%29%29

Alexis

> On Apr 25, 2017, at 23:18, Jinzhou Zhang  wrote:
> 
> Hi there,
> 
> I am writing a simple macro `if-let` that tried to bind the condition to a 
> variable.
> 
> ```
> (define-simple-macro (if-let (~describe "binding pairs" [binding:expr 
> value:expr])
> (~describe "\"then\" clause" then:expr)
> (~describe "\"else\" clause" else:expr))
>  (let ([val value])
>(if val (match-let ([binding val]) then) else)))
> ```
> 
> I finished the macro and start to write unit tests for it. Then I realized 
> that
> the "binding" should not working in "else" statement. That means:
> 
> ```
> (if-let [it #f]
>  'true
>  it   ; <- should report "unbound identifier".
> )
> ```
> 
> However when I tried the following code:
> 
> ```
> (check-exn exn:fail?
>   (lambda ()
> (if-let [it #f]
> (fail "if-let: wrong-branch")
> it)))
> 
> ```
> 
> It gives error:
> 
> ```
> it: unbound identifier in module
> ```
> 
> So the question is how to catch the "unbound identifier" exception for unit 
> test?
> 
> 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.


[racket-users] Re: How to make unit test for error "unbound identifier"?

2017-04-26 Thread Jinzhou Zhang
Sorry for forgot to mention Racket version. It is 6.8.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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 make unit test for error "unbound identifier"?

2017-04-26 Thread Jinzhou Zhang
Hi there,

I am writing a simple macro `if-let` that tried to bind the condition to a 
variable.

```
(define-simple-macro (if-let (~describe "binding pairs" [binding:expr 
value:expr])
 (~describe "\"then\" clause" then:expr)
 (~describe "\"else\" clause" else:expr))
  (let ([val value])
(if val (match-let ([binding val]) then) else)))
```

I finished the macro and start to write unit tests for it. Then I realized that
the "binding" should not working in "else" statement. That means:

```
(if-let [it #f]
  'true
  it   ; <- should report "unbound identifier".
)
```

However when I tried the following code:

```
(check-exn exn:fail?
   (lambda ()
 (if-let [it #f]
 (fail "if-let: wrong-branch")
 it)))

```

It gives error:

```
 it: unbound identifier in module
```

So the question is how to catch the "unbound identifier" exception for unit 
test?

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.