Re: [racket-users] raise an exception in a generator

2019-02-19 Thread David Storrs
How about this?:



On Tue, Feb 19, 2019, 9:57 PM Kees-Jochem Wehrmeijer 
wrote:

> Basically when I call the function throw. So e.g.
>
> (define mygenerator (generator ()
>(with-handlers ([exn:fail? (lambda (e) 42)])
>  (yield 1)
>  (yield 2)
>  (yield 3
>
> > (mygenerator)
> 1
> > (throw mygenerator)
> 42
>

(define (mygenerator [throw? #f])
 (if throw? 42 (begin (yield 1)(yield 2)(yield 3)))

> (mygenerator)
1
> (mygenerator 'throw)
42

What sort of thing would you use this technique for? You aren't actually
throwing anything, because you trap and discard the exception before
returning a value normally.



> On Tue, Feb 19, 2019 at 6:20 PM David Storrs 
> wrote:
>
>> Under what circumstances would you want it to throw? When the generator
>> runs out, or...?
>>
>> On Tue, Feb 19, 2019, 3:59 PM Kees-Jochem Wehrmeijer 
>> wrote:
>>
>>> Hi,
>>>
>>> Python allows to call a .throw() method on a generator. I was wondering
>>> if Racket generators have a similar feature. From the docs it doesn't seem
>>> to have that. One way I could see around this is to set a parameter and
>>> then check for that parameter in the generator and raise an exception based
>>> on that. I could imagine writing a macro, e.g. yield-except, that does that
>>> check. The disadvantage would be that users would have to remember to use
>>> yield-except instead of regular yield in the generator.
>>>
>>> Are there any other clever workarounds that I'm missing?
>>>
>>> Thanks,
>>> Kees
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Racket Users" group.
>>> To unsubscribe from this group and 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] raise an exception in a generator

2019-02-19 Thread Kees-Jochem Wehrmeijer
Basically when I call the function throw. So e.g.

(define mygenerator (generator ()
   (with-handlers ([exn:fail? (lambda (e) 42)])
 (yield 1)
 (yield 2)
 (yield 3

> (mygenerator)
1
> (throw mygenerator)
42

On Tue, Feb 19, 2019 at 6:20 PM David Storrs  wrote:

> Under what circumstances would you want it to throw? When the generator
> runs out, or...?
>
> On Tue, Feb 19, 2019, 3:59 PM Kees-Jochem Wehrmeijer 
> wrote:
>
>> Hi,
>>
>> Python allows to call a .throw() method on a generator. I was wondering
>> if Racket generators have a similar feature. From the docs it doesn't seem
>> to have that. One way I could see around this is to set a parameter and
>> then check for that parameter in the generator and raise an exception based
>> on that. I could imagine writing a macro, e.g. yield-except, that does that
>> check. The disadvantage would be that users would have to remember to use
>> yield-except instead of regular yield in the generator.
>>
>> Are there any other clever workarounds that I'm missing?
>>
>> Thanks,
>> Kees
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and 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: pkgs still has no docs? (was: Re: [racket-users] Questions about Scribble docs)

2019-02-19 Thread David Storrs
Speaking of things with no docs, the abnf package seems intriguing. Does
anyone have a short summary or example?

On Tue, Feb 19, 2019, 5:14 PM John Clements 
wrote:

> Looks like… this is still the case? Specifically, reloading
> pkgs.racket-lang.org still shows that all packages are missing
> documentation. I thought I’d seen a message suggesting that this was
> resolved, but it appears I was mistaken.
>
> John
>
>
> > On Feb 16, 2019, at 8:08 PM, David Storrs 
> wrote:
> >
> > On Sat, Feb 16, 2019 at 9:18 PM Greg Hendershott
> >  wrote:
> >>
> >> The package web site seems to think no packages have been built: The
> >> "Most recent build results" item is blank for every of the dozen
> >> packages I just checked.
> >
> > Ah, that would do it.  Thanks.
> >
> >>
> >> So I think that's one problem.
> >>
> >>
> >> When that's working normally, as it usually does, there are two levels
> >> of refresh:
> >>
> >> 1. The package catalog server points to e.g. your most recent commit
> >> on Git{Hub Lab}.com. You push a new commit. The package catalog might
> >> take an hour before it notices. This is the thing you can "kick" by
> >> logging in and choosing "Rescan my packges".
> >>
> >> 2. The build server runs daily. This is what builds your docs as part
> >> of building your package. So, even if it were working, now, it might
> >> take 24 hours. There's no way to nudge this AFAIK.
> >>
> >>
> >> On Sat, Feb 16, 2019 at 8:21 PM David Storrs 
> wrote:
> >>>
> >>> Do I need to do something particular to make the package server notice
> >>> my documentation?  I've got a scribblings/struct-plus-plus.scrbl file
> >>> but the package server is still listing it as "needs documentation".
> >>>
> >>> Separate but related, when I install a module and it builds the
> >>> documentation, is there a way to make it integrate with the built-in
> >>> docs so that I can load it in the browser and search?
> >>>
> >>> --
> >>> You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> >>> To unsubscribe from this group and 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.


Re: [racket-users] raise an exception in a generator

2019-02-19 Thread David Storrs
Under what circumstances would you want it to throw? When the generator
runs out, or...?

On Tue, Feb 19, 2019, 3:59 PM Kees-Jochem Wehrmeijer 
wrote:

> Hi,
>
> Python allows to call a .throw() method on a generator. I was wondering if
> Racket generators have a similar feature. From the docs it doesn't seem to
> have that. One way I could see around this is to set a parameter and then
> check for that parameter in the generator and raise an exception based on
> that. I could imagine writing a macro, e.g. yield-except, that does that
> check. The disadvantage would be that users would have to remember to use
> yield-except instead of regular yield in the generator.
>
> Are there any other clever workarounds that I'm missing?
>
> Thanks,
> Kees
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and 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] Bending use of include-template to my needs (or, macro results as macro arguments)

2019-02-19 Thread Matthew Butterick

> On Feb 19, 2019, at 2:33 PM, Brian Adkins  wrote:
> 
> Awesome - that did the trick. I'm confused as to why it helped to inject STR 
> into the lexical context - it ends up being just a string, and it was working 
> fine with respect to loading the template. I would think the fix would be to 
> inject include-template into the lexical context. I suppose it must have 
> something to do with how the include-template macro is dealing with that 
> argument. 

When `with-syntax` finds a datum (like a string) on the right side of a 
pattern-binding expression, it silently coerces it to a syntax object with the 
macro-definition scope attached (which in this case, was not the right scope).

Ordinarily you wouldn't want to move `include-template` into the lexical 
context of the calling site, because you're relying on retaining the binding it 
has at the macro-definition site.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Bending use of include-template to my needs (or, macro results as macro arguments)

2019-02-19 Thread Brian Adkins
On Tuesday, February 19, 2019 at 5:06:32 PM UTC-5, Matthew Butterick wrote:
>
>
>
> On Feb 19, 2019, at 1:28 PM, Brian Adkins  > wrote:
>
> Oops - I spoke too soon. It appears the lexical context is unavailable to 
> the template when include-template is used in this manner. 
>
>
> Ah right, one has to inject STR into the same lexical context, like so:
>
>
> #lang racket
> (require web-server/templates)
>
> (define-syntax (include-template/named stx)
>   (syntax-case stx ()
> [(_ NAME)
>  (with-syntax ([STR (datum->syntax #'NAME (string-append 
> "../views/authentication/" (symbol->string (syntax-e #'NAME)) ".html"))]) 
>#'(include-template STR))]))
>
> (define (login request)
>   (include-template/named login))
>


Awesome - that did the trick. I'm confused as to why it helped to inject 
STR into the lexical context - it ends up being just a string, and it was 
working fine with respect to loading the template. I would think the fix 
would be to inject include-template into the lexical context. I suppose it 
must have something to do with how the include-template macro is dealing 
with that argument. 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] mixed integer programming using glpk

2019-02-19 Thread 'John Clements' via Racket Users
I’m pleased to announce that I had a good reason to extend the glpk package to 
provide an interface to glpk’s mixed integer programming package; this means 
that if you can express your problem as a sequence of linear constraints on a 
set of variables where some of them need to be integers, you can use glpk to 
tackle this problem.

Docs here:

https://docs.racket-lang.org/glpk/index.html?q=glpk

install with “raco pkg install GLPK” or purchase wherever racket pkgs are sold.

Complaints and pull requests welcome!

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.


pkgs still has no docs? (was: Re: [racket-users] Questions about Scribble docs)

2019-02-19 Thread 'John Clements' via Racket Users
Looks like… this is still the case? Specifically, reloading 
pkgs.racket-lang.org still shows that all packages are missing documentation. I 
thought I’d seen a message suggesting that this was resolved, but it appears I 
was mistaken.

John


> On Feb 16, 2019, at 8:08 PM, David Storrs  wrote:
> 
> On Sat, Feb 16, 2019 at 9:18 PM Greg Hendershott
>  wrote:
>> 
>> The package web site seems to think no packages have been built: The
>> "Most recent build results" item is blank for every of the dozen
>> packages I just checked.
> 
> Ah, that would do it.  Thanks.
> 
>> 
>> So I think that's one problem.
>> 
>> 
>> When that's working normally, as it usually does, there are two levels
>> of refresh:
>> 
>> 1. The package catalog server points to e.g. your most recent commit
>> on Git{Hub Lab}.com. You push a new commit. The package catalog might
>> take an hour before it notices. This is the thing you can "kick" by
>> logging in and choosing "Rescan my packges".
>> 
>> 2. The build server runs daily. This is what builds your docs as part
>> of building your package. So, even if it were working, now, it might
>> take 24 hours. There's no way to nudge this AFAIK.
>> 
>> 
>> On Sat, Feb 16, 2019 at 8:21 PM David Storrs  wrote:
>>> 
>>> Do I need to do something particular to make the package server notice
>>> my documentation?  I've got a scribblings/struct-plus-plus.scrbl file
>>> but the package server is still listing it as "needs documentation".
>>> 
>>> Separate but related, when I install a module and it builds the
>>> documentation, is there a way to make it integrate with the built-in
>>> docs so that I can load it in the browser and search?
>>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Racket Users" group.
>>> To unsubscribe from this group and 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.


Re: [racket-users] Bending use of include-template to my needs (or, macro results as macro arguments)

2019-02-19 Thread Matthew Butterick


> On Feb 19, 2019, at 1:28 PM, Brian Adkins  wrote:
> 
> Oops - I spoke too soon. It appears the lexical context is unavailable to the 
> template when include-template is used in this manner. 


Ah right, one has to inject STR into the same lexical context, like so:


#lang racket
(require web-server/templates)

(define-syntax (include-template/named stx)
  (syntax-case stx ()
[(_ NAME)
 (with-syntax ([STR (datum->syntax #'NAME (string-append 
"../views/authentication/" (symbol->string (syntax-e #'NAME)) ".html"))]) 
   #'(include-template STR))]))

(define (login request)
  (include-template/named login))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Bending use of include-template to my needs (or, macro results as macro arguments)

2019-02-19 Thread Brian Adkins


On Tuesday, February 19, 2019 at 4:03:02 PM UTC-5, Brian Adkins wrote:
>
> On Tuesday, February 19, 2019 at 1:45:43 PM UTC-5, Matthew Butterick wrote:
>>
>>
>> On Feb 19, 2019, at 8:25 AM, Brian Adkins  wrote:
>>
>> But, I'm guessing that the include-template macro is unable to consume 
>> the output of my view macro. Is there anything I can do to get (view login) 
>> to be expanded prior to when include-template needs it?
>>
>>
>> Wrap `include-template` with your own macro that generates the string you 
>> want?
>>
>> #lang racket
>> (require web-server/templates)
>>
>> (define-syntax (include-template/named stx)
>>   (syntax-case stx ()
>> [(_ NAME)
>>  (with-syntax ([STR (string-append "../views/authentication/" 
>> (symbol->string (syntax-e #'NAME)) ".html")]) 
>>#'(include-template STR))]))
>>
>> (define (login request)
>>   (include-template/named login))
>>
>>
> That's perfect Matthew - thanks! 
>

Oops - I spoke too soon. It appears the lexical context is unavailable to 
the template when include-template is used in this manner. 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Bending use of include-template to my needs (or, macro results as macro arguments)

2019-02-19 Thread Brian Adkins
On Tuesday, February 19, 2019 at 1:45:43 PM UTC-5, Matthew Butterick wrote:
>
>
> On Feb 19, 2019, at 8:25 AM, Brian Adkins  > wrote:
>
> But, I'm guessing that the include-template macro is unable to consume the 
> output of my view macro. Is there anything I can do to get (view login) to 
> be expanded prior to when include-template needs it?
>
>
> Wrap `include-template` with your own macro that generates the string you 
> want?
>
> #lang racket
> (require web-server/templates)
>
> (define-syntax (include-template/named stx)
>   (syntax-case stx ()
> [(_ NAME)
>  (with-syntax ([STR (string-append "../views/authentication/" 
> (symbol->string (syntax-e #'NAME)) ".html")]) 
>#'(include-template STR))]))
>
> (define (login request)
>   (include-template/named login))
>
>
That's perfect Matthew - 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] raise an exception in a generator

2019-02-19 Thread Kees-Jochem Wehrmeijer
Hi,

Python allows to call a .throw() method on a generator. I was wondering if 
Racket generators have a similar feature. From the docs it doesn't seem to 
have that. One way I could see around this is to set a parameter and then 
check for that parameter in the generator and raise an exception based on 
that. I could imagine writing a macro, e.g. yield-except, that does that 
check. The disadvantage would be that users would have to remember to use 
yield-except instead of regular yield in the generator.

Are there any other clever workarounds that I'm missing?

Thanks,
Kees

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Transfer code from "intermediate student with lamnda" to "Pretty big"

2019-02-19 Thread orenpa11
Hi
Is it possible to transfer code from "intermediate student with lamnda" to 
"Pretty big"
for exmple :

(require 2htdp/image)
(require 2htdp/universe)


(define (join-together ls1 ls2)
  (local 
[; help : [ListOf X] -> [ListOf X]
 ; (help ls1) drops the invariant argument ls2
 (define (help ls1)
   (cond
 [(empty? ls1) ls2]
 [else (cons (first ls1) 
 (help (rest ls1)))]))]
(help ls1)))

(check-expect (join-together '() '(a b c d e f)) '(a b c d e f))
(check-expect (join-together '(a)  '(b c d e f)) '(a b c d e f))
(check-expect (join-together '(a b)  '(c d e f)) '(a b c d e f))
(check-expect (join-together '(a b c ) '(d e f)) '(a b c d e f))
(check-expect (join-together '(a b c d)  '(e f)) '(a b c d e f))
(check-expect (join-together '(a b c d e)  '(f)) '(a b c d e f))
(check-expect (join-together '(a b c d e f) '()) '(a b c d e f))



Thanks,
Or

p.s. I get the error

check-expect: undefined;
 cannot reference an identifier before its definition

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Bending use of include-template to my needs (or, macro results as macro arguments)

2019-02-19 Thread Matthew Butterick

> On Feb 19, 2019, at 8:25 AM, Brian Adkins  wrote:
> 
> But, I'm guessing that the include-template macro is unable to consume the 
> output of my view macro. Is there anything I can do to get (view login) to be 
> expanded prior to when include-template needs it?

Wrap `include-template` with your own macro that generates the string you want?

#lang racket
(require web-server/templates)

(define-syntax (include-template/named stx)
  (syntax-case stx ()
[(_ NAME)
 (with-syntax ([STR (string-append "../views/authentication/" 
(symbol->string (syntax-e #'NAME)) ".html")]) 
   #'(include-template STR))]))

(define (login request)
  (include-template/named login))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Bending use of include-template to my needs (or, macro results as macro arguments)

2019-02-19 Thread Brian Adkins
I would like to take the following web request handler:

(define (login request)
  (render-string
   (include-template "../views/authentication/login.html")))

and eventually get to something like:

(define (login request)
  (render login))

My current lack of understanding with respect to macros is limiting me :) 
For now, I'd be content with the following:

(define (login request)
  (render-string
   (include-template (view login

which I tried to get to work with this macro:

(define-syntax-rule (view name)
  (string-append "../views/authentication/" (symbol->string (quote name)) 
".html"))

But, I'm guessing that the include-template macro is unable to consume the 
output of my view macro. Is there anything I can do to get (view login) to 
be expanded prior to when include-template needs it?

Thanks,
Brian


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