Re: [racket-users] Re: lambda and the equivalent define / "defun"

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

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

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

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

- Jon

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


Re: [racket-users] Re: lambda and the equivalent define / "defun"

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

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

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


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

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


Re: [racket-users] aws package fails against google cloud storage

2016-09-06 Thread Greg Hendershott
Until this thread today, I wasn't even aware the AWS package could be
used with GCS.

It was a fair amount of work to update things to use v4 sig a year ago:

  https://github.com/greghendershott/aws/milestone/5?closed=1

If only I'd known, I could have used GCS compatibility as an excuse
not to do that. ;)

Seriously, IIUC the issue is that newer AWS data centers don't even
support v2 sig anymore. One of the few users of the AWS package that I
know of had requested v4 so they could use Frankfurt.


By the way, I myself am not an active user of this package. Originally
I undertook it as one of the
suggested-ways-people-could-help-with-Racket. Although I've had
limited time lately, I'm happy to maintain it. Having said that I'd
welcome any active user who wanted to do more with it than I current
have time to do.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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: lambda and the equivalent define / "defun"

2016-09-06 Thread Sanjeev Sharma
Thanks, that's helpful

I am having trouble coming up with a quick and easy shorthand to recur on the 
rest parameter - is there a standard way to cdr down this list without an 
intermediary helper function that takes out the raise-nesting-depth effect? 

Recursion on the base define (the one with the rest parameter) always adds 
another layer of nesting for the rest parameter - the first time recurring one 
must cdr, all the other times one must fiddle with car & cdr and what I'm doing 
has been prone working for the first few iterations but eventually 
arity-mismatches.


On Tuesday, September 6, 2016 at 7:39:59 AM UTC-4, gneuner2 wrote:
> On Sun, 4 Sep 2016 10:36:21 -0700 (PDT), Sanjeev Sharma wrote: 
> 
> >two "x" 's also work
> >
> >(define list (lambda x x))
> 
> (lambda x x x) works because the evaluation of the middle x is a side
> effect which is ignored.  It still will work if you change it to,
> e.g., (lambda x 'q x)  or (lambda x 42 x) ... changing the middle x to
> anything that is not a variable.
> 
> 
> Extra information:   [ignore if you know this already]
> 
> (lambda x x) is the right way to define list ... but it works sort of
> incidentally because Scheme permits "rest" parameters which gather
> multiple arguments into a list.   
> 
> (define (list . x) x) also is equivalent and the syntax makes clear
> that x is intended to be a rest parameter.
> 
> 
> (lambda v v) is different from (lambda (v) v).  The unadorned v in the
> 1st indicates that v is a single rest parameter which will gather all
> the arguments into a list.  The parentheses in the 2nd indicate that v
> is a normal parameter which will take on a single value [which may be
> a deliberately passed list].
> 
> -> ((lambda v v) 1 2 3) 
> => '(1 2 3)
> 
> -> ((lambda (v) v) 1 2 3) 
> => #: arity mismatch
> 
> 
> Rest parameters may be combined with required parameters as in 
> (lambda (x . v) ... )  which is different from (lambda (x v) ... ).
> The dot in the parameter 1st indicates that v is a rest parameter.  In
> the 2nd, both x and v are normal parameters.
> 
> -> ((lambda (x . v) v) 1 2 3) 
> => '(2 3)
> 
> -> ((lambda (x . v) x) 1 2 3) 
> => 1
> 
> -> ((lambda (x v) v) 1 2 3) 
> => #: arity mismatch
> 
> -> ((lambda (x v) v) 1 2) 
> => 2
> 
> 
> A function can have only a single rest parameter [or none]. 
> 
> 
> Hope this helps,
> George

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


Re: [racket-users] aws package fails against google cloud storage

2016-09-06 Thread 'John Clements' via Racket Users

> On Sep 6, 2016, at 11:59 AM, 'John Clements' via Racket Users 
>  wrote:
> 
> 
>> On Sep 6, 2016, at 11:40 AM, 'John Clements' via Racket Users 
>>  wrote:
>> 
>> 
>>> On Sep 6, 2016, at 11:19 AM, 'John Clements' via Racket Users 
>>>  wrote:
>>> 
>>> I’m in the process of updating some old code that used the PLaneT version 
>>> of aws to communicate with google cloud storage (yes, google cloud storage 
>>> apparently uses the s3 protocol). Using the current aws package with Google 
>>> Cloud Storage yields responses looking like this:
>>> 
>>> root@cp-test-class:/tmp# racket ./aws-script.rkt 
>>> aws: HTTP/1.1 400 Bad Request
>>> X-GUploader-UploadID: 
>>> AEnB2UrulPLTOAcTyMyO_szDGocgmqOf4nmP3cmZwPQ--j3HGPyaLenL2eVxcM60nlkHy5n37KzEDzhSD3XXK3azWmcSy7v-rw
>>> Content-Type: application/xml; charset=UTF-8
>>> Content-Length: 211
>>> Date: Tue, 06 Sep 2016 18:05:48 GMT
>>> Expires: Tue, 06 Sep 2016 18:05:48 GMT
>>> Cache-Control: private, max-age=0
>>> Server: UploadServer
>>> 
>>> >> encoding='UTF-8'?>MissingSecurityHeaderYour 
>>> request was missing a required header.x-amz-date 
>>> required for AWS S3 V4 signature
>>> HTTP 400 "Bad Request". AWS Code="MissingSecurityHeader" Message="Your 
>>> request was missing a required header."
>>> context...:
>>> check-response
>>> /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:344:33
>>> /root/.racket/6.6/pkgs/aws/aws/s3.rkt:272:42
>>> /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:340:33
>>> /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:340:33
>>> request/redirect/uri
>>> ...higher-order.rkt:340:33
>>> /root/.racket/6.6/pkgs/aws/aws/s3.rkt:259:2: loop
>>> ls
>>> /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:344:33
>>> /tmp/aws-script.rkt: [running body]
>>> 
>>> … and I’m trying to figure out whether 
>>> a) google cloud storage changed (e.g., it now uses V4 signatures rather 
>>> than V2 signatures or something), or
>>> b) your aws code changed (e.g., it now uses V4 signatuers rather than V2 
>>> signatures … or something).
>>> 
>>> Can you shed any light on this? I’m about to start digging into the meaning 
>>> of the x-amz-date header.
>>> 
>>> Alternatively, I’d also love to hear about people currently using the aws 
>>> package to interact with google cloud storage!
>> 
>> Sad face: I’ve done the obvious test—try running against the PLaneT 
>> version—and the error is gone. This leads me to believe that upgrades to the 
>> aws package have made it incompatible with google cloud storage.
>> 
>> Obvious fixes that I don’t like:
>> 
>> 1) stop using google cloud storage, starting using Amazon S3.
>> 2) use the old PLaneT version instead of the shiny new pkg version.
>> 
>> Any other suggestions? 
> 
> Bleh… git bisected, and it does appear that the problem is the change to V4 
> signatures, first seen in 9e1019a86426d5563417accc1ae9c7810110774d.
> 
> Sigh.

Okay, well, just to finish up this conversation with myself for posterity … It 
looks like google cloud storage doesn’t get really support V4 signatures, 
though they may be working on it, at least as of today, per this github thread:

https://github.com/saltstack/salt/issues/31522

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.


Re: [racket-users] Order of reduction rules in Redex

2016-09-06 Thread Dupéron Georges
Le mardi 6 septembre 2016 20:39:37 UTC+2, Sam Caldwell a écrit :
> I'm not sure what it is you want. Do you want the reduction relation to be 
> deterministic? If so then you need to decide which order is the "right" one.
> 
> You can do this by adding a "lifted-less expression" to your grammar

Thanks a lot, Sam, this works like a charm!

I wanted the relation order to be deterministic indeed, but I wasn't sure if it 
was the appropriate solution, or if this was an XY problem that needed a 
completely different approach.

Regards,
Georges Dupéron

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] aws package fails against google cloud storage

2016-09-06 Thread 'John Clements' via Racket Users

> On Sep 6, 2016, at 11:40 AM, 'John Clements' via Racket Users 
>  wrote:
> 
> 
>> On Sep 6, 2016, at 11:19 AM, 'John Clements' via Racket Users 
>>  wrote:
>> 
>> I’m in the process of updating some old code that used the PLaneT version of 
>> aws to communicate with google cloud storage (yes, google cloud storage 
>> apparently uses the s3 protocol). Using the current aws package with Google 
>> Cloud Storage yields responses looking like this:
>> 
>> root@cp-test-class:/tmp# racket ./aws-script.rkt 
>> aws: HTTP/1.1 400 Bad Request
>> X-GUploader-UploadID: 
>> AEnB2UrulPLTOAcTyMyO_szDGocgmqOf4nmP3cmZwPQ--j3HGPyaLenL2eVxcM60nlkHy5n37KzEDzhSD3XXK3azWmcSy7v-rw
>> Content-Type: application/xml; charset=UTF-8
>> Content-Length: 211
>> Date: Tue, 06 Sep 2016 18:05:48 GMT
>> Expires: Tue, 06 Sep 2016 18:05:48 GMT
>> Cache-Control: private, max-age=0
>> Server: UploadServer
>> 
>> > encoding='UTF-8'?>MissingSecurityHeaderYour 
>> request was missing a required header.x-amz-date required 
>> for AWS S3 V4 signature
>> HTTP 400 "Bad Request". AWS Code="MissingSecurityHeader" Message="Your 
>> request was missing a required header."
>> context...:
>>  check-response
>>  /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:344:33
>>  /root/.racket/6.6/pkgs/aws/aws/s3.rkt:272:42
>>  /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:340:33
>>  /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:340:33
>>  request/redirect/uri
>>  ...higher-order.rkt:340:33
>>  /root/.racket/6.6/pkgs/aws/aws/s3.rkt:259:2: loop
>>  ls
>>  /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:344:33
>>  /tmp/aws-script.rkt: [running body]
>> 
>> … and I’m trying to figure out whether 
>> a) google cloud storage changed (e.g., it now uses V4 signatures rather than 
>> V2 signatures or something), or
>> b) your aws code changed (e.g., it now uses V4 signatuers rather than V2 
>> signatures … or something).
>> 
>> Can you shed any light on this? I’m about to start digging into the meaning 
>> of the x-amz-date header.
>> 
>> Alternatively, I’d also love to hear about people currently using the aws 
>> package to interact with google cloud storage!
> 
> Sad face: I’ve done the obvious test—try running against the PLaneT 
> version—and the error is gone. This leads me to believe that upgrades to the 
> aws package have made it incompatible with google cloud storage.
> 
> Obvious fixes that I don’t like:
> 
> 1) stop using google cloud storage, starting using Amazon S3.
> 2) use the old PLaneT version instead of the shiny new pkg version.
> 
> Any other suggestions? 

Bleh… git bisected, and it does appear that the problem is the change to V4 
signatures, first seen in 9e1019a86426d5563417accc1ae9c7810110774d.

Sigh.

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] Racket module creation in org-mode?

2016-09-06 Thread Lawrence Bottorff
Just wondering if creating a module always has to be based on a .rkt file? 
Would there be any way to create, say, modules (one or more) in an org-mode 
file, perhaps one module per babel code block? . . . Trying to get org-mode to 
be more "modular."

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] aws package fails against google cloud storage

2016-09-06 Thread 'John Clements' via Racket Users

> On Sep 6, 2016, at 11:19 AM, 'John Clements' via Racket Users 
>  wrote:
> 
> I’m in the process of updating some old code that used the PLaneT version of 
> aws to communicate with google cloud storage (yes, google cloud storage 
> apparently uses the s3 protocol). Using the current aws package with Google 
> Cloud Storage yields responses looking like this:
> 
> root@cp-test-class:/tmp# racket ./aws-script.rkt 
> aws: HTTP/1.1 400 Bad Request
> X-GUploader-UploadID: 
> AEnB2UrulPLTOAcTyMyO_szDGocgmqOf4nmP3cmZwPQ--j3HGPyaLenL2eVxcM60nlkHy5n37KzEDzhSD3XXK3azWmcSy7v-rw
> Content-Type: application/xml; charset=UTF-8
> Content-Length: 211
> Date: Tue, 06 Sep 2016 18:05:48 GMT
> Expires: Tue, 06 Sep 2016 18:05:48 GMT
> Cache-Control: private, max-age=0
> Server: UploadServer
> 
>  encoding='UTF-8'?>MissingSecurityHeaderYour 
> request was missing a required header.x-amz-date required 
> for AWS S3 V4 signature
> HTTP 400 "Bad Request". AWS Code="MissingSecurityHeader" Message="Your 
> request was missing a required header."
>  context...:
>   check-response
>   /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:344:33
>   /root/.racket/6.6/pkgs/aws/aws/s3.rkt:272:42
>   /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:340:33
>   /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:340:33
>   request/redirect/uri
>   ...higher-order.rkt:340:33
>   /root/.racket/6.6/pkgs/aws/aws/s3.rkt:259:2: loop
>   ls
>   /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:344:33
>   /tmp/aws-script.rkt: [running body]
> 
> … and I’m trying to figure out whether 
> a) google cloud storage changed (e.g., it now uses V4 signatures rather than 
> V2 signatures or something), or
> b) your aws code changed (e.g., it now uses V4 signatuers rather than V2 
> signatures … or something).
> 
> Can you shed any light on this? I’m about to start digging into the meaning 
> of the x-amz-date header.
> 
> Alternatively, I’d also love to hear about people currently using the aws 
> package to interact with google cloud storage!

Sad face: I’ve done the obvious test—try running against the PLaneT version—and 
the error is gone. This leads me to believe that upgrades to the aws package 
have made it incompatible with google cloud storage.

Obvious fixes that I don’t like:

1) stop using google cloud storage, starting using Amazon S3.
2) use the old PLaneT version instead of the shiny new pkg version.

Any other suggestions? 

Thanks in advance,

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.


Re: [racket-users] Order of reduction rules in Redex

2016-09-06 Thread Sam Caldwell
I'm not sure what it is you want. Do you want the reduction relation to be
deterministic? If so then you need to decide which order is the "right" one.

You can do this by adding a "lifted-less expression" to your grammar, such
as

(define-extended-language simple+lifted+hole+temp simple+lifted
  ;; elided
  (q v
 number
 (+ q q)))

and then restricting your definitions of contexts:

;; left-to-right
(C hole
 (begin σ ... C σ ...)
 (define v C)
 (+ C e)
 (+ q C))

or

;; right-to-left
(C hole
 (begin σ ... C σ ...)
 (define v C)
 (+ C q)
 (+ e C))

This is basically the same approach as defining a call-by-value lambda
calculus, except instead of values you have
expressions-that-do-not-contain-lifted. This is covered in the Long
Tutorial[1], specifically in section 2.4

[1] https://docs.racket-lang.org/redex/redex2015.html

- Sam Caldwell

On Tue, Sep 6, 2016 at 1:39 PM, Dupéron Georges  wrote:

> Hi all!
>
> I'm trying out redex, and I defined a simple language with (define v e)
> statements. I also defined an extended language, which allows expressions
> to be (lifted v' e'). A (lifted v' e') expression is replaced by v', and a
> definition (define v' e') is lifted to the top-level, just before the
> current statement.
>
> I tried to define a reduction from the simple+lifted language to the
> simple language. It makes the lifted definitions bubble up until they reach
> the top-level, and inserts them before their containing statement.
>
> Unfortunately, my reduction is ambiguous: when reducing the program
> (define result (+ (lifted x 1) (lifted y 2))), both lifted definitions can
> bubble up first and be inserted before the other. Therefore,
> apply-reduction-relation* returns two valid results:
>
> (begin (define x 1) (define y 2) (define result (+ x y)))
> (begin (define y 2) (define x 1) (define result (+ x y)))
>
> How can I avoid this problem?
>
> See the attached file or http://pasterack.org/pastes/44574 for the full
> code.
>
> Thanks!
> Georges Dupéron
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and 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] aws package fails against google cloud storage

2016-09-06 Thread 'John Clements' via Racket Users
I’m in the process of updating some old code that used the PLaneT version of 
aws to communicate with google cloud storage (yes, google cloud storage 
apparently uses the s3 protocol). Using the current aws package with Google 
Cloud Storage yields responses looking like this:

root@cp-test-class:/tmp# racket ./aws-script.rkt 
aws: HTTP/1.1 400 Bad Request
X-GUploader-UploadID: 
AEnB2UrulPLTOAcTyMyO_szDGocgmqOf4nmP3cmZwPQ--j3HGPyaLenL2eVxcM60nlkHy5n37KzEDzhSD3XXK3azWmcSy7v-rw
Content-Type: application/xml; charset=UTF-8
Content-Length: 211
Date: Tue, 06 Sep 2016 18:05:48 GMT
Expires: Tue, 06 Sep 2016 18:05:48 GMT
Cache-Control: private, max-age=0
Server: UploadServer

 MissingSecurityHeaderYour 
request was missing a required header.x-amz-date required 
for AWS S3 V4 signature
HTTP 400 "Bad Request". AWS Code="MissingSecurityHeader" Message="Your request 
was missing a required header."
  context...:
   check-response
   /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:344:33
   /root/.racket/6.6/pkgs/aws/aws/s3.rkt:272:42
   /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:340:33
   /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:340:33
   request/redirect/uri
   ...higher-order.rkt:340:33
   /root/.racket/6.6/pkgs/aws/aws/s3.rkt:259:2: loop
   ls
   /usr/racket/collects/racket/contract/private/arrow-higher-order.rkt:344:33
   /tmp/aws-script.rkt: [running body]

… and I’m trying to figure out whether 
a) google cloud storage changed (e.g., it now uses V4 signatures rather than V2 
signatures or something), or
b) your aws code changed (e.g., it now uses V4 signatuers rather than V2 
signatures … or something).

Can you shed any light on this? I’m about to start digging into the meaning of 
the x-amz-date header.

Alternatively, I’d also love to hear about people currently using the aws 
package to interact with google cloud storage!

Many thanks,

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.


Re: [racket-users] whether to use gui framework

2016-09-06 Thread Alexis King
I don’t use the GUI stuff much, so take this with a grain of salt,
but my guess is that you will definitely want to use framework if
you need syntax coloring. The color:text% component does a lot of
work to implement syntax coloring on top of the relatively primitive
text% component (which is actually missing a lot of other functionality
that framework provides), and you’ll get the benefit of automatic
compatibility with existing Racket language lexers.

> On Sep 6, 2016, at 12:29 AM, Neil Van Dyke  wrote:
> 
> If I want to write a GUI program with a simple syntax-colored text language 
> for a UI[*]... do I want to use just `editor-canvas%`, or will the additional 
> work of using `framework` save me a lot of work in the end?
> 
> [*] One frame, consisting only of a text editor, with line-oriented language 
> syntax coloring, and syntax-sensitive context menus and double-clicking.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] whether to use gui framework

2016-09-06 Thread Matthew Flatt
The framework classes are very likely to pay off for that application.
I used them toward a similar end in the `slideshow-repl` package.

At Tue, 6 Sep 2016 03:29:30 -0400, Neil Van Dyke wrote:
> If I want to write a GUI program with a simple syntax-colored text 
> language for a UI[*]... do I want to use just `editor-canvas%`, or will 
> the additional work of using `framework` save me a lot of work in the end?
> 
> [*] One frame, consisting only of a text editor, with line-oriented 
> language syntax coloring, and syntax-sensitive context menus and 
> double-clicking.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Order of reduction rules in Redex

2016-09-06 Thread Dupéron Georges
Hi all!

I'm trying out redex, and I defined a simple language with (define v e) 
statements. I also defined an extended language, which allows expressions to be 
(lifted v' e'). A (lifted v' e') expression is replaced by v', and a definition 
(define v' e') is lifted to the top-level, just before the current statement.

I tried to define a reduction from the simple+lifted language to the simple 
language. It makes the lifted definitions bubble up until they reach the 
top-level, and inserts them before their containing statement.

Unfortunately, my reduction is ambiguous: when reducing the program (define 
result (+ (lifted x 1) (lifted y 2))), both lifted definitions can bubble up 
first and be inserted before the other. Therefore, apply-reduction-relation* 
returns two valid results:

(begin (define x 1) (define y 2) (define result (+ x y)))
(begin (define y 2) (define x 1) (define result (+ x y)))

How can I avoid this problem?

See the attached file or http://pasterack.org/pastes/44574 for the full code.

Thanks!
Georges Dupéron

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


lifted-experiment.rkt
Description: Binary data


Re: [racket-users] Positioning GUI controls in contact with one another

2016-09-06 Thread David Storrs
On Tue, Sep 6, 2016 at 1:15 AM, Jens Axel Søgaard 
wrote:

> Dave wrote:
> > I'm on OSX 10.11.  I'm working on a spreadsheet application, and my
> current plan is to have each cell be
> > represented as a separate text control.[1]
>
> This potentially leads to many controls (even with your optimization in
> footnote [1]).
>
> Consider displaying (a section of) the spreadsheet in a canvas.
> Simply draw lines and text to get the grid with contents.
> When the user clicks at a cell, create a control to receive the input,
> then remove it afterwards.
> Or perhaps even have a single control that are shown/hidden.
>
> See an older discussion here:
> https://groups.google.com/d/msg/racket-users/xiKAHjIDmt8/m9-SGZuUVfsJ
>
> /Jens Axel
>
>
Thanks, that's helpful.



Other topic:  I feel like I ask a lot of questions on this list and it
occasionally makes me feel like a nudge.  The helpfulness of the community
is really impressive; people always come back with answers quickly, and the
answers are always helpful.  Thank you all.


Dave





>
>
> 2016-09-06 0:03 GMT+02:00 Robby Findler :
>
>> I haven't seen buttons in spreadsheet cells in excel, but maybe I'm
>> taking your words too literally?
>>
>> Have you considered using canvas% objects instead of buttons? They
>> should give you the flexibility you're after.
>>
>> Robby
>>
>> On Mon, Sep 5, 2016 at 4:23 PM, David Storrs 
>> wrote:
>> > How do I find the actual minimum size of a GUI control (e.g. a button)
>> > without the space around it?
>> >
>> >
>> > I'm on OSX 10.11.  I'm working on a spreadsheet application, and my
>> current
>> > plan is to have each cell be represented as a separate text
>> control.[1]  I
>> > need to have these controls be in contact with one another the way they
>> are
>> > in Excel or any other spreadsheet.  (That is, there is no empty space
>> > between the controls.) By default Racket wants to put significant space
>> > between controls and I've been unable to figure out how to stop this in
>> a
>> > clean, cross-platform way.
>> >
>> > Here's what I've tried:
>> >
>> > (define frame (new frame% [label "Example"]))
>> > (define panel (new horizontal-panel% [parent frame]))
>> > (define left-btn (new button% [parent panel] [label "Left"]))
>> > (define right-btn (new button% [parent panel] [label "Right"]))
>> > (define (shrinkwrap c)
>> >   (send c horiz-margin 0)
>> >   (send c vert-margin 0))
>> > (void (map shrinkwrap (list left-btn right-btn panel)))
>> > (for ((c (list panel frame)))
>> >  (send c spacing 0))
>> > ;;These won't work because get-min-graphical-size is 84 and will
>> trump
>> > the requested size
>> > (send left-btn min-width 70)
>> > (send right-btn min-width 70)
>> >
>> > (send frame show #t)
>> >
>> > This shows the frame with two buttons arranged horizontally.  There is
>> > significant space around each button and between the two buttons.  I
>> want
>> > there to be no space between them.
>> >
>> >
>> > Both the left and right buttons have minimum graphical sizes of
>> (84,32), as
>> > shown by:
>> > (begin
>> >   (define-values (w h) (send left-btn get-graphical-min-size))
>> >   (displayln
>> >(format "left button min w/h: ~a,~a" w h)))
>> > ;; Same for right-btn
>> >
>> > A quick test shows that I can get the behavior I need by overriding
>> > place-children:
>> >
>> > (define squishable-panel%
>> >   (class horizontal-panel%
>> >  (define/override (place-children info w h)
>> >(displayln "Called place-children")
>> >'((0 0 70 20) (70 0 70 20)))
>> >  (super-new)))
>> > (define panel (new squishable-panel% [parent frame]))
>> > ;;  ...all other declarations stay the same...
>> >
>> > The problem is that I got the above numbers by experimentation.
>> > get-graphical-min-size returns the size *with* the spacing that I'm
>> trying
>> > to get rid of, which defeats the purpose.  (Also, why??  That's not the
>> size
>> > of the button, it's the size of the button plus some extra space.)  I
>> don't
>> > see a clean way to go from the GMS to the actual minimum size when
>> dealing
>> > with cross-platform size differences and the fact that Windows is
>> > pixel-based and OSX is drawing-unit-based.
>> >
>> > Any suggestions?
>> >
>> >
>> > Dave
>> >
>> > [1] I may need to do some optimizations later instead of representing
>> empty
>> > cells as controls, but that's for later.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Racket Users" group.
>> > To unsubscribe from this group and 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

Re: [racket-users] Positioning GUI controls in contact with one another

2016-09-06 Thread David Storrs
On Mon, Sep 5, 2016 at 3:03 PM, Robby Findler 
wrote:

> I haven't seen buttons in spreadsheet cells in excel, but maybe I'm
> taking your words too literally?
>

Ah, sorry, I phrased that poorly.  I'm thinking of things like the header
on a column, which you can click to make it sort that column.



> Have you considered using canvas% objects instead of buttons? They
> should give you the flexibility you're after.
>

I hadn't.  Thanks, that's a good idea.  I've been playing with it yesterday
and today and having better success, although still not total.

Dave


>
> Robby
>
> On Mon, Sep 5, 2016 at 4:23 PM, David Storrs 
> wrote:
> > How do I find the actual minimum size of a GUI control (e.g. a button)
> > without the space around it?
> >
> >
> > I'm on OSX 10.11.  I'm working on a spreadsheet application, and my
> current
> > plan is to have each cell be represented as a separate text control.[1]
> I
> > need to have these controls be in contact with one another the way they
> are
> > in Excel or any other spreadsheet.  (That is, there is no empty space
> > between the controls.) By default Racket wants to put significant space
> > between controls and I've been unable to figure out how to stop this in a
> > clean, cross-platform way.
> >
> > Here's what I've tried:
> >
> > (define frame (new frame% [label "Example"]))
> > (define panel (new horizontal-panel% [parent frame]))
> > (define left-btn (new button% [parent panel] [label "Left"]))
> > (define right-btn (new button% [parent panel] [label "Right"]))
> > (define (shrinkwrap c)
> >   (send c horiz-margin 0)
> >   (send c vert-margin 0))
> > (void (map shrinkwrap (list left-btn right-btn panel)))
> > (for ((c (list panel frame)))
> >  (send c spacing 0))
> > ;;These won't work because get-min-graphical-size is 84 and will
> trump
> > the requested size
> > (send left-btn min-width 70)
> > (send right-btn min-width 70)
> >
> > (send frame show #t)
> >
> > This shows the frame with two buttons arranged horizontally.  There is
> > significant space around each button and between the two buttons.  I want
> > there to be no space between them.
> >
> >
> > Both the left and right buttons have minimum graphical sizes of (84,32),
> as
> > shown by:
> > (begin
> >   (define-values (w h) (send left-btn get-graphical-min-size))
> >   (displayln
> >(format "left button min w/h: ~a,~a" w h)))
> > ;; Same for right-btn
> >
> > A quick test shows that I can get the behavior I need by overriding
> > place-children:
> >
> > (define squishable-panel%
> >   (class horizontal-panel%
> >  (define/override (place-children info w h)
> >(displayln "Called place-children")
> >'((0 0 70 20) (70 0 70 20)))
> >  (super-new)))
> > (define panel (new squishable-panel% [parent frame]))
> > ;;  ...all other declarations stay the same...
> >
> > The problem is that I got the above numbers by experimentation.
> > get-graphical-min-size returns the size *with* the spacing that I'm
> trying
> > to get rid of, which defeats the purpose.  (Also, why??  That's not the
> size
> > of the button, it's the size of the button plus some extra space.)  I
> don't
> > see a clean way to go from the GMS to the actual minimum size when
> dealing
> > with cross-platform size differences and the fact that Windows is
> > pixel-based and OSX is drawing-unit-based.
> >
> > Any suggestions?
> >
> >
> > Dave
> >
> > [1] I may need to do some optimizations later instead of representing
> empty
> > cells as controls, but that's for later.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and 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] Re: lambda and the equivalent define / "defun"

2016-09-06 Thread George Neuner
On Sun, 4 Sep 2016 10:36:21 -0700 (PDT), Sanjeev Sharma
 wrote:

>two "x" 's also work
>
>(define list (lambda x x))

(lambda x x x) works because the evaluation of the middle x is a side
effect which is ignored.  It still will work if you change it to,
e.g., (lambda x 'q x)  or (lambda x 42 x) ... changing the middle x to
anything that is not a variable.


Extra information:   [ignore if you know this already]

(lambda x x) is the right way to define list ... but it works sort of
incidentally because Scheme permits "rest" parameters which gather
multiple arguments into a list.   

(define (list . x) x) also is equivalent and the syntax makes clear
that x is intended to be a rest parameter.


(lambda v v) is different from (lambda (v) v).  The unadorned v in the
1st indicates that v is a single rest parameter which will gather all
the arguments into a list.  The parentheses in the 2nd indicate that v
is a normal parameter which will take on a single value [which may be
a deliberately passed list].

-> ((lambda v v) 1 2 3) 
=> '(1 2 3)

-> ((lambda (v) v) 1 2 3) 
=> #: arity mismatch


Rest parameters may be combined with required parameters as in 
(lambda (x . v) ... )  which is different from (lambda (x v) ... ).
The dot in the parameter 1st indicates that v is a rest parameter.  In
the 2nd, both x and v are normal parameters.

-> ((lambda (x . v) v) 1 2 3) 
=> '(2 3)

-> ((lambda (x . v) x) 1 2 3) 
=> 1

-> ((lambda (x v) v) 1 2 3) 
=> #: arity mismatch

-> ((lambda (x v) v) 1 2) 
=> 2


A function can have only a single rest parameter [or none]. 


Hope this helps,
George

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


Re: [racket-users] syntax-parse in typed racket

2016-09-06 Thread Sourav Datta
On Monday, September 5, 2016 at 10:54:57 PM UTC+5:30, Matthias Felleisen wrote:
> The easiest and proper fix is to write typed macros for typed modules. Below 
> is a naive but straightforward solution. It would be better if 
> define-memoized fished out the type declaration for f and used it to add 
> domain types for arg-s...
> 
> #lang typed/racket
> 
> (require (for-syntax syntax/parse))
> 
> (: memoize (All (r a ...)
> (-> (-> a ... a r)
> (-> a ... a r
> (define (memoize fn)
>   (let ([store : (HashTable Any r) (make-hash)])
> (define (memfn . [args : a ... a])
>   (hash-ref store args
> (lambda ()
>   (let ([result : r (apply fn args)])
> (hash-set! store args result)
> result
> memfn))
> 
> (: fibo (-> Integer Integer))
> (define fibo (memoize (lambda ([n : Integer])
> (if (<= n 1)
> 1
> (+ (fibo (- n 1))
>(fibo (- n 2)))
> 
> (define-syntax (define-memoized stx)
>   (syntax-parse stx ;; I didn’t get the ‘:’ syntax right the first time, so I 
> gave up on that 
> [(_ (fn-name:id {arg t} ...) Tresult body ...)
>  #'(begin
>  (: fn-name (-> t ... Tresult))
>  (define fn-name (memoize (lambda ({arg : t} ...) body ...]))
> 
> 
> (define-memoized (fib {n Integer}) Integer
>   (if (<= n 1)
>   1
>   (+ (fib (- n 1))
>  (fib (- n 2)
> 
> (fib 10)
> 
> 
> 
> > On Sep 5, 2016, at 3:11 AM, Sourav Datta  wrote:
> > 
> > Another day, another typed racket question!
> > 
> > I was experimenting with memoize library in Racket and noticed that it does 
> > not always work with typed racket functions (or, may be I was not 
> > 'require'ing it properly). So I came up with this crude implementation 
> > below and it seems to be working for one or more arguments:
> > 
> > #lang typed/racket
> > 
> > (: memoize (All (r a ...)
> >(-> (-> a ... a r)
> >  (-> a ... a r
> > (define (memoize fn)
> >  (let ([store : (HashTable Any r) (make-hash)])
> >(define (memfn . [args : a ... a])
> >  (hash-ref store args
> >(lambda ()
> >  (let ([result : r (apply fn args)])
> >(hash-set! store args result)
> >result
> >memfn))
> > 
> > So the typical fibo function with this memoization function would look like:
> > 
> > (: fibo (-> Integer Integer))
> > (define fibo (memoize (lambda ([n : Integer])
> >(if (<= n 1)
> >1
> >(+ (fibo (- n 1))
> >   (fibo (- n 2)))
> > 
> > However, what I wanted is to define a macro similar to define/memo like in 
> > the Racket memoize package. A first approach like below did not work:
> > 
> > (define-syntax (define-memoized stx)
> >  (syntax-parse stx
> >[(_ (fn-name:id arg:id ...) body ...+)
> > #'(define fn-name (memoize (lambda (arg ...) body ...)))]))
> > 
> > The error comes in (<= n 1) call where it is given Any but expecting 
> > Integer. The problem is that the syntax splits the function definition in a 
> > lambda expression and then passes to memoize function, whose result is then 
> > assigned to the function name. The lambda expression without type 
> > annotation assumes that the arguments are Any. 
> > 
> > So in this case, is there any way we could write a macro on top of the 
> > above memoize that can identify the types of the underlying function and 
> > annotate the lambda accordingly - or is there any other way this could be 
> > achieved?
> > 
> > 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.

This approach seems like the easiest and flexible way to define the macro. Just 
to add, here's another crude version of the macro I came up with where we can 
specify the type declaration inside the macro, rather than outside which gives 
some way to use it in the function definition:

(define-syntax (memoized stx)
  (syntax-parse stx
((_ type-decl (define (fn-name:id arg:id ...+) body ...+))
 (let ([type-decl-v (syntax->datum #'type-decl)])
   (if (not (and (list? type-decl-v)
 (eqv? (car type-decl-v) ':)))
   (error "Bad type declaration!")
   (let* ([new-fn-name (gensym)]
  [old-fn-name (syntax->datum #'fn-name)]
  [new-type-decl-v (map (lambda (s) (if (equal? s old-fn-name) 
new-fn-name s)) type-decl-v)])
 (with-syntax ([fn-temp-name (datum->syntax stx new-fn-name)]

Re: [racket-users] Positioning GUI controls in contact with one another

2016-09-06 Thread Jens Axel Søgaard
Dave wrote:
> I'm on OSX 10.11.  I'm working on a spreadsheet application, and my
current plan is to have each cell be
> represented as a separate text control.[1]

This potentially leads to many controls (even with your optimization in
footnote [1]).

Consider displaying (a section of) the spreadsheet in a canvas.
Simply draw lines and text to get the grid with contents.
When the user clicks at a cell, create a control to receive the input, then
remove it afterwards.
Or perhaps even have a single control that are shown/hidden.

See an older discussion here:
https://groups.google.com/d/msg/racket-users/xiKAHjIDmt8/m9-SGZuUVfsJ

/Jens Axel



2016-09-06 0:03 GMT+02:00 Robby Findler :

> I haven't seen buttons in spreadsheet cells in excel, but maybe I'm
> taking your words too literally?
>
> Have you considered using canvas% objects instead of buttons? They
> should give you the flexibility you're after.
>
> Robby
>
> On Mon, Sep 5, 2016 at 4:23 PM, David Storrs 
> wrote:
> > How do I find the actual minimum size of a GUI control (e.g. a button)
> > without the space around it?
> >
> >
> > I'm on OSX 10.11.  I'm working on a spreadsheet application, and my
> current
> > plan is to have each cell be represented as a separate text control.[1]
> I
> > need to have these controls be in contact with one another the way they
> are
> > in Excel or any other spreadsheet.  (That is, there is no empty space
> > between the controls.) By default Racket wants to put significant space
> > between controls and I've been unable to figure out how to stop this in a
> > clean, cross-platform way.
> >
> > Here's what I've tried:
> >
> > (define frame (new frame% [label "Example"]))
> > (define panel (new horizontal-panel% [parent frame]))
> > (define left-btn (new button% [parent panel] [label "Left"]))
> > (define right-btn (new button% [parent panel] [label "Right"]))
> > (define (shrinkwrap c)
> >   (send c horiz-margin 0)
> >   (send c vert-margin 0))
> > (void (map shrinkwrap (list left-btn right-btn panel)))
> > (for ((c (list panel frame)))
> >  (send c spacing 0))
> > ;;These won't work because get-min-graphical-size is 84 and will
> trump
> > the requested size
> > (send left-btn min-width 70)
> > (send right-btn min-width 70)
> >
> > (send frame show #t)
> >
> > This shows the frame with two buttons arranged horizontally.  There is
> > significant space around each button and between the two buttons.  I want
> > there to be no space between them.
> >
> >
> > Both the left and right buttons have minimum graphical sizes of (84,32),
> as
> > shown by:
> > (begin
> >   (define-values (w h) (send left-btn get-graphical-min-size))
> >   (displayln
> >(format "left button min w/h: ~a,~a" w h)))
> > ;; Same for right-btn
> >
> > A quick test shows that I can get the behavior I need by overriding
> > place-children:
> >
> > (define squishable-panel%
> >   (class horizontal-panel%
> >  (define/override (place-children info w h)
> >(displayln "Called place-children")
> >'((0 0 70 20) (70 0 70 20)))
> >  (super-new)))
> > (define panel (new squishable-panel% [parent frame]))
> > ;;  ...all other declarations stay the same...
> >
> > The problem is that I got the above numbers by experimentation.
> > get-graphical-min-size returns the size *with* the spacing that I'm
> trying
> > to get rid of, which defeats the purpose.  (Also, why??  That's not the
> size
> > of the button, it's the size of the button plus some extra space.)  I
> don't
> > see a clean way to go from the GMS to the actual minimum size when
> dealing
> > with cross-platform size differences and the fact that Windows is
> > pixel-based and OSX is drawing-unit-based.
> >
> > Any suggestions?
> >
> >
> > Dave
> >
> > [1] I may need to do some optimizations later instead of representing
> empty
> > cells as controls, but that's for later.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and 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] whether to use gui framework

2016-09-06 Thread Neil Van Dyke
If I want to write a GUI program with a simple syntax-colored text 
language for a UI[*]... do I want to use just `editor-canvas%`, or will 
the additional work of using `framework` save me a lot of work in the end?


[*] One frame, consisting only of a text editor, with line-oriented 
language syntax coloring, and syntax-sensitive context menus and 
double-clicking.


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