[racket-users] Unicode identifiers

2018-05-15 Thread N. Raghavendra
I just found that

> (define φoo→β=αρ "Foo→b=ar")
> φoo→β=αρ
"Foo→b=ar"
>(call-with-output-file "/tmp/foo.txt"
   (λ (out)
   (display (xml-remove-markup) out))
   #:exists 'replace)

etc., work.  That's nice.

In general, is it possible to declare, e.g., '→' as equivalent to '->'
in identifiers?  Then, I can use

> (string→symbol "map")

instead of

> (string->symbol "map")

Thanks,
Raghu.

--
N. Raghavendra , http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/

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

2018-05-15 Thread N. Raghavendra
At 2018-05-14T11:40:05+05:30, N. Raghavendra wrote:

> I'll update my installation of the package after a few hours.

Sorry, I missed this.  I had updated my installation of the package
after a couple of hours on that day, and sxml:document works as
expected, for local file URLs.  HTTP URLs, as you had mentioned
elsewhere, don't work.

Raghu.

-- 
N. Raghavendra , http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] ssax:make-parser

2018-05-15 Thread N. Raghavendra
At 2018-05-15T17:36:44-04:00, John Clements wrote:

> Interestingly, it looks like this change is a deliberate one, made by
> Ryan Culpepper back in 2011. Here’s the relevant commit:

Thanks for tracing that change.

Raghu.

-- 
N. Raghavendra , http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] html-parsing package 5.0 changes

2018-05-15 Thread Neil Van Dyke
I made a few changes to how the `html-parsing` package (version 5.0) 
parses invalid HTML named character entity references.


In the unlikely event that these changes break you, please email me 
directly, and we'll try to figure it out.


http://www.neilvandyke.org/racket/html-parsing/#%28part._.History%29

I think the Racket package catalog will update soon.

This package is very old code, and is in minimal "sustaining 
engineering" mode, but these changes were prompted by an immediate 
real-world need.


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and 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] ssax:make-parser

2018-05-15 Thread 'John Clements' via Racket Users
Interestingly, it looks like this change is a deliberate one, made by Ryan 
Culpepper back in 2011. Here’s the relevant commit:

commit 738bf41d106f4ecd9111bbefabfd78bec8dc2202
Author: Ryan Culpepper 
Date:   Tue Nov 22 02:46:32 2011 -0700

bypass ssax/ssax module
trim exports from main (breaks backwards compat!)

diff --git a/main.rkt b/main.rkt
index bf3530d..89f27d3 100644
--- a/main.rkt
+++ b/main.rkt
@@ -27,5 +27,11 @@
 (provide (all-from-out "modif.rkt"))
 (provide (all-from-out "serializer.rkt"))
 
-(require "ssax/ssax.rkt")
-(provide (all-from-out "ssax/ssax.rkt"))
+(require "ssax/multi-parser.rkt"
+ "ssax/sxpathlib.rkt"
+ "ssax/SXML-tree-trans.rkt"
+ "ssax/SSAX-code.rkt")
+(provide ssax:multi-parser
+ (all-from-out "ssax/sxpathlib.rkt")
+ pre-post-order
+ ssax:xml->sxml)

Ryan, do you know why you put ssax:multi-parser in, but not ssax:make-parser? 

Cheers!

John


> On May 15, 2018, at 6:42 AM, N. Raghavendra  wrote:
> 
> I was trying out Oleg Kiselyov's example
> 
> http://okmij.org/ftp/Scheme/remove-markup.scm
> 
> which illustrates the use of `ssax:make-parser'.  I have a couple of
> questions:
> 
> 1. To call ssax-make-parser, I had to require both sxml and
> sxml/ssax/ssax.  Is that the correct way of doing it?
> 
> 2. It seems an important function, and I was wondering why the sxml
> module does not provide it, the way it does ssax:xml->sxml, so that one
> doesn't need to further require sxml/ssax/ssax.  I see that sxml
> provides ssax:multi-parser.  Is it similar to ssax:make-parser?
> 
> Thanks,
> Raghu.
> 
> --
> N. Raghavendra , http://www.retrotexts.net/
> Harish-Chandra Research Institute, http://www.hri.res.in/
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and 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] handin-server submissions

2018-05-15 Thread James Yoo
Hi, everyone

I'm currently in charge of a handin-server instance for a course at my 
university. We're currently experiencing issues where students are unable 
to handin their work, receiving this error message:

login error: user (STUDENT_USERNAME) not in assignment/section lab-01

I think I've configured config.rktd correctly, with "lab-01" being in the 
correct active-dirs s-expression.

Does anyone have an idea of what's going on? I'd be happy to share my 
config.rktd file.

Thanks!
James 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Edmond's Blossom Algorithm

2018-05-15 Thread Jens Axel Søgaard
Thanks!   Just what I needed.

/Jens Axel


2018-05-15 13:04 GMT+02:00 Daniel Prager :

> A more low-tech approach ...
>
> #lang racket
>
> (require threading)
>
> (define students '(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z))
>
> (define indexes (for/hash ([s students] [i (in-naturals)])
>   (values s i)))
>
> ; A -> 0, B -> 1, ...
> (define (index student)
>   (hash-ref indexes student))
>
> ; Generate synthetic preferences for 'student'
> ;
> (define (random-preferences student)
>   (~> students
>   (remove student _)
>   shuffle
>   (take 3)))
>
> ; Generate synthetic preferences for all the students
> ;
> (define preferences
>   (for/hash ([s students])
> (define prefs (random-preferences s))
> (displayln (list s prefs))
> (values s prefs)))
>
> ; Score 1 if a likes b; 0 otherwise
> ;
> (define (likes a b)
>   (if (~> preferences (hash-ref a) (member b _)) 1 0))
>
> ; Score 2 is a and b like each other
> ; Score 1 if only one likes the other
> ; Score 0 otherwise
> ;
> (define (pair-score a b)
>   (+ (likes a b) (likes b a)))
>
> ; Find all the pairings where the pair-score is n
> ;
> (define (scores-exactly n)
>   (shuffle
>(for*/list ([a students]
>[b students]
>#:when (and (< (index a) (index b))
>(= (pair-score a b) n)))
>  (list a b
>
> ; What is the total score and pair-wise score for these pairs?
> ;
> (define (score-assignment pairs)
>   (define scored-pairs
> (for/list ([p pairs])
>   (list p (apply pair-score p
>   (list (for/sum ([p scored-pairs])
>   (last p))
> scored-pairs))
>
> ; First try tp pair up students who want to work together
> ; Next students where at least one wants to work with the other
> ; Finally there may be some unlucky ones
> ;
> (define (assign-pairs [options (apply append (map scores-exactly '(2 1
> 0)))]
>   [remaining students]
>   [acc null])
>   (if (null? remaining)
>   (score-assignment (reverse acc))
>   (match-let ([(list a b) (first options)])
> (if (and (member a remaining)
>  (member b remaining))
> (assign-pairs (rest options)
>   (~>> remaining (remove a) (remove b))
>   (cons (first options) acc))
> (assign-pairs (rest options)
>   remaining
>   acc)
>
> (newline)
> (argmax first (for/list ([i 10]) (assign-pairs)))
>
>
>
> *Sample output*
>
> (A (D T B))
> (B (I A L))
> (C (B J P))
> (D (K O P))
> (E (K Z B))
> (F (C O Y))
> (G (E C I))
> (H (I W M))
> (I (V G W))
> (J (H Z T))
> (K (O M Q))
> (L (K V T))
> (M (Y R E))
> (N (M D J))
> (O (N K P))
> (P (W R C))
> (Q (T O E))
> (R (C F Y))
> (S (N E U))
> (T (B S H))
> (U (V N K))
> (V (L U Q))
> (W (B O X))
> (X (A Q Z))
> (Y (T B R))
> (Z (V T N))
>
> '(18
>   (((G I) 2)
>((U V) 2)
>((A B) 2)
>((C P) 2)
>((K O) 2)
>((R Y) 2)
>((E S) 1)
>((J Z) 1)
>((D N) 1)
>((L T) 1)
>((H W) 1)
>((Q X) 1)
>((F M) 0)))
>



-- 
-- 
Jens Axel Søgaard

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


Re: [racket-users] Macro from list to class init

2018-05-15 Thread Matthias Felleisen


What you seen to want is eval not a macro, because the data (including field 
names) don’t exist at compile time: 

#lang racket/gui
(define-namespace-anchor top)
(define frame (new frame% [label "test"]))
(define data `((stretchable-width #t) (label "test") (parent ,frame)))
(eval `(new button% ,@data) (namespace-anchor->namespace top))
(send frame show #t)


> On May 15, 2018, at 5:11 AM, Denis Michiels  wrote:
> 
> Hi,
> 
> For more explanation about my goal, here is "wrong" version :
> 
> #lang racket/gui
> 
> (define frame (new frame% [label "test"]))
> (send frame show #t)
> 
> (define-syntax (mk-widget stx)
>  (syntax-case stx ()
>[(_ (list (cons (datum->syntax k) v) ...))
> #'(new button% [k v] ...)]))
> 
> ; Work, but not my end goal
> (mk-widget (list (cons 'label "init")
> (cons 'parent frame)
> (cons 'stretchable-width #t)))
> 
> ; My end goal
> ; (define d (list (cons 'label "init") (cons 'parent frame)))
> ; (mk-widget d)
> 
> 
> It works in the first case because I think that the variable is never
> created.
> My goal is the second case, where it is given by a variable. But I hope
> this can help a little. Is there a way to have a `list->syntax`?
> 
> Thank you for reading,
> Denis
> 
> Denis Michiels  writes:
> 
>> Hello,
>> 
>> thank you for this start of response, but my goal is to be more general,
>> and not to make specific action (here, the label must be the first in
>> the list, ...).
>> 
>> In fact, I want to "rewrite" the `new` function, but only with raw
>> data-type (like list and cons). Or at least, something that transform
>> raw data-type to the `new` function.
>> 
>> And I hope it could be used for any class (at least for GUI class). Is
>> that possible or I'm trying to do something that is not the goal of
>> macro in Racket?
>> 
>> kind regards,
>> Denis
>> 
>> 
>> Matthias Felleisen  writes:
>> 
 On May 14, 2018, at 6:55 AM, Denis Michiels  wrote:
 
 Hello,
 
 I'm trying to build a macro to be able to do :
 
 ```
 (define data (list (cons 'label "My button")
  (cons 'stretchable-width #t)))
 
 (my-macro button% data)
 ```
 
 to be translated in  :
 
 ```
 (new button% [label "My button"] [stretchable-width #t])
 ```
 
 (I take gui example, and incomplete (like no frame) but it is to show my
 goal)
 
 Unfortunately, I didn't manage well macro in Racket...
 Can someone help me, or have a hint how to manage this macro?
 
>>> 
>>> #lang racket/gui
>>> 
>>> (define data '((label "My button") (stretchable-width #t)))
>>> 
>>> (define-syntax (mk-but stx)
>>>  (syntax-case stx ()
>>>[(_ data)
>>> #'(let ()
>>> (match-define (cons label others) data)
>>> (define button (make-object button% (second label) frame))
>>> (for ((o others))
>>>   (match-define (list m val) o)
>>>   (dynamic-send button m val)))]))
>>> 
>>> 
>>> (define frame (new frame% [label "test"]))
>>> 
>>> (mk-but data)
>>> 
>>> (send frame show #t)
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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 handle circular 'requires'

2018-05-15 Thread David Storrs
Incidentally, sorry for the mangled formatting / narrow margins that
my emails keep having.  I'm not doing that, it's coming from GMail.

On Tue, May 15, 2018 at 10:06 AM, David Storrs  wrote:
> On Tue, May 15, 2018 at 1:28 AM, Matthew Butterick  wrote:
>> To add to your pile of options, because you said "certain error conditions":
>> perhaps you might `raise` an exception in the db code that gets caught by
>> the network code (using `with-handlers`). In this way the dependency only
>> runs one direction (network module imports db module) but the db module can
>> still propagate messages to the network module (by going "backward" through
>> the existing calling chain with an exception, rather than "forward" by
>> calling into the db module).
>>
>> Here is a toy example of a `db` module that keeps kicking back an exception
>> to a `network` module until it gets zero, no circularity needed:
>>
>> #lang racket
>>
>> (module db racket
>>   (provide f)
>>   (define (f val)
>> (if (zero? val)
>> 'finally-a-zero!
>> (raise val
>>
>> (module network racket
>>   (require (submod ".." db))
>>   (let loop ([maybe-err-int #f])
>> (with-handlers ([integer? loop])
>>   (when maybe-err-int
>> (displayln (number->string maybe-err-int)))
>>   (f (random 10)
>>
>> (require 'network)
>
> Brilliant!  That's perfect, thank you.
>
> On that subject, I note the existence of handy/try on the package
> server.  It provides a macro for exception handling that combines
> 'with-handlers' and 'dynamic-wind' while having better end weight than
> the former.  It comes in several flavors, the most general of them
> being:
>
> (try [(do database thing here)  (write files to disk)]
>   [pre (mark records in DB as locked and lock files on disk before
> the main body of the try runs)]
>   [catch (exn:fail:db (lambda (e) (displayln (~a "Database failed
> with message: " (exn-message e)
>  (exn:fail:filesystem (lambda (e) (displayln (~a
> "failed to write file: " (exn-message e)]
>   [finally (unlock records in DB, unlock files)])
>
> This reduces to:
>
> (with-handlers ([(exn:fail:db (lambda (e) (displayln (~a "Database
> failed with message: " (exn-message e)]
>  [(exn:fail:filesystem (lambda (e) (displayln
> (~a "failed to write file: " (exn-message e)])
>   (dynamic-wind
>  (thunk (mark records in DB as locked and lock files on disk
> before the main body of the try runs))
>  (thunk (do database thing here)  (write files to disk))
>  (thunk (unlock records in DB, unlock files
>
> I believe the 'try' version to be better because it is syntactically
> simpler, explicitly labels the different parts of the 'dynamic-wind'
> instead of requiring that you know what they are, and provides better
> end weight in the 'with-handlers' -- the body of the code is up front
> so you know what is supposed to happen, while the error handling /
> preflight / cleanup are tucked away at the end so that you already
> know the context and don't need to think about them while dealing with
> the happy path.
>
> The 'pre', 'catch', and 'finally' blocks are all optional and leaving
> them out simply defatalizes and returns the exception if there is one.
> I should create a version that lets you put 'pre' ahead of the body if
> that's what you want, but I haven't done that yet.
>
>
>>
>>
>> On May 14, 2018, at 10:28 AM, David Storrs  wrote:
>>
>> This worked fine until now, but I've gotten to a point where they're
>> circular -- the network code needs to receive the chunk and then
>> forward it to the DB code, but if certain error conditions come up
>> then the DB code needs to tell the network code to re-request the
>> data.
>>
>> There's various ways I could work around this (simplest being to put
>> all the functions in one file), but I'm wondering if there's a
>> recommended way?  C would solve this with a .h file.  Perl would solve
>> it with function prototypes (or simply be able to sort it out without
>> intervention).  What is the preferred Racket way, or am I simply not
>> thinking about it correctly?
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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 handle circular 'requires'

2018-05-15 Thread David Storrs
On Tue, May 15, 2018 at 1:28 AM, Matthew Butterick  wrote:
> To add to your pile of options, because you said "certain error conditions":
> perhaps you might `raise` an exception in the db code that gets caught by
> the network code (using `with-handlers`). In this way the dependency only
> runs one direction (network module imports db module) but the db module can
> still propagate messages to the network module (by going "backward" through
> the existing calling chain with an exception, rather than "forward" by
> calling into the db module).
>
> Here is a toy example of a `db` module that keeps kicking back an exception
> to a `network` module until it gets zero, no circularity needed:
>
> #lang racket
>
> (module db racket
>   (provide f)
>   (define (f val)
> (if (zero? val)
> 'finally-a-zero!
> (raise val
>
> (module network racket
>   (require (submod ".." db))
>   (let loop ([maybe-err-int #f])
> (with-handlers ([integer? loop])
>   (when maybe-err-int
> (displayln (number->string maybe-err-int)))
>   (f (random 10)
>
> (require 'network)

Brilliant!  That's perfect, thank you.

On that subject, I note the existence of handy/try on the package
server.  It provides a macro for exception handling that combines
'with-handlers' and 'dynamic-wind' while having better end weight than
the former.  It comes in several flavors, the most general of them
being:

(try [(do database thing here)  (write files to disk)]
  [pre (mark records in DB as locked and lock files on disk before
the main body of the try runs)]
  [catch (exn:fail:db (lambda (e) (displayln (~a "Database failed
with message: " (exn-message e)
 (exn:fail:filesystem (lambda (e) (displayln (~a
"failed to write file: " (exn-message e)]
  [finally (unlock records in DB, unlock files)])

This reduces to:

(with-handlers ([(exn:fail:db (lambda (e) (displayln (~a "Database
failed with message: " (exn-message e)]
 [(exn:fail:filesystem (lambda (e) (displayln
(~a "failed to write file: " (exn-message e)])
  (dynamic-wind
 (thunk (mark records in DB as locked and lock files on disk
before the main body of the try runs))
 (thunk (do database thing here)  (write files to disk))
 (thunk (unlock records in DB, unlock files

I believe the 'try' version to be better because it is syntactically
simpler, explicitly labels the different parts of the 'dynamic-wind'
instead of requiring that you know what they are, and provides better
end weight in the 'with-handlers' -- the body of the code is up front
so you know what is supposed to happen, while the error handling /
preflight / cleanup are tucked away at the end so that you already
know the context and don't need to think about them while dealing with
the happy path.

The 'pre', 'catch', and 'finally' blocks are all optional and leaving
them out simply defatalizes and returns the exception if there is one.
I should create a version that lets you put 'pre' ahead of the body if
that's what you want, but I haven't done that yet.


>
>
> On May 14, 2018, at 10:28 AM, David Storrs  wrote:
>
> This worked fine until now, but I've gotten to a point where they're
> circular -- the network code needs to receive the chunk and then
> forward it to the DB code, but if certain error conditions come up
> then the DB code needs to tell the network code to re-request the
> data.
>
> There's various ways I could work around this (simplest being to put
> all the functions in one file), but I'm wondering if there's a
> recommended way?  C would solve this with a .h file.  Perl would solve
> it with function prototypes (or simply be able to sort it out without
> intervention).  What is the preferred Racket way, or am I simply not
> thinking about it correctly?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] ssax:make-parser

2018-05-15 Thread N. Raghavendra
I was trying out Oleg Kiselyov's example

http://okmij.org/ftp/Scheme/remove-markup.scm

which illustrates the use of `ssax:make-parser'.  I have a couple of
questions:

1. To call ssax-make-parser, I had to require both sxml and
sxml/ssax/ssax.  Is that the correct way of doing it?

2. It seems an important function, and I was wondering why the sxml
module does not provide it, the way it does ssax:xml->sxml, so that one
doesn't need to further require sxml/ssax/ssax.  I see that sxml
provides ssax:multi-parser.  Is it similar to ssax:make-parser?

Thanks,
Raghu.

--
N. Raghavendra , http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] Edmond's Blossom Algorithm

2018-05-15 Thread Daniel Prager
A more low-tech approach ...

#lang racket

(require threading)

(define students '(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z))

(define indexes (for/hash ([s students] [i (in-naturals)])
  (values s i)))

; A -> 0, B -> 1, ...
(define (index student)
  (hash-ref indexes student))

; Generate synthetic preferences for 'student'
;
(define (random-preferences student)
  (~> students
  (remove student _)
  shuffle
  (take 3)))

; Generate synthetic preferences for all the students
;
(define preferences
  (for/hash ([s students])
(define prefs (random-preferences s))
(displayln (list s prefs))
(values s prefs)))

; Score 1 if a likes b; 0 otherwise
;
(define (likes a b)
  (if (~> preferences (hash-ref a) (member b _)) 1 0))

; Score 2 is a and b like each other
; Score 1 if only one likes the other
; Score 0 otherwise
;
(define (pair-score a b)
  (+ (likes a b) (likes b a)))

; Find all the pairings where the pair-score is n
;
(define (scores-exactly n)
  (shuffle
   (for*/list ([a students]
   [b students]
   #:when (and (< (index a) (index b))
   (= (pair-score a b) n)))
 (list a b

; What is the total score and pair-wise score for these pairs?
;
(define (score-assignment pairs)
  (define scored-pairs
(for/list ([p pairs])
  (list p (apply pair-score p
  (list (for/sum ([p scored-pairs])
  (last p))
scored-pairs))

; First try tp pair up students who want to work together
; Next students where at least one wants to work with the other
; Finally there may be some unlucky ones
;
(define (assign-pairs [options (apply append (map scores-exactly '(2 1 0)))]
  [remaining students]
  [acc null])
  (if (null? remaining)
  (score-assignment (reverse acc))
  (match-let ([(list a b) (first options)])
(if (and (member a remaining)
 (member b remaining))
(assign-pairs (rest options)
  (~>> remaining (remove a) (remove b))
  (cons (first options) acc))
(assign-pairs (rest options)
  remaining
  acc)

(newline)
(argmax first (for/list ([i 10]) (assign-pairs)))



*Sample output*

(A (D T B))
(B (I A L))
(C (B J P))
(D (K O P))
(E (K Z B))
(F (C O Y))
(G (E C I))
(H (I W M))
(I (V G W))
(J (H Z T))
(K (O M Q))
(L (K V T))
(M (Y R E))
(N (M D J))
(O (N K P))
(P (W R C))
(Q (T O E))
(R (C F Y))
(S (N E U))
(T (B S H))
(U (V N K))
(V (L U Q))
(W (B O X))
(X (A Q Z))
(Y (T B R))
(Z (V T N))

'(18
  (((G I) 2)
   ((U V) 2)
   ((A B) 2)
   ((C P) 2)
   ((K O) 2)
   ((R Y) 2)
   ((E S) 1)
   ((J Z) 1)
   ((D N) 1)
   ((L T) 1)
   ((H W) 1)
   ((Q X) 1)
   ((F M) 0)))

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


Re: [racket-users] Macro from list to class init

2018-05-15 Thread Denis Michiels
Hi,

For more explanation about my goal, here is "wrong" version :

#lang racket/gui

(define frame (new frame% [label "test"]))
(send frame show #t)

(define-syntax (mk-widget stx)
  (syntax-case stx ()
[(_ (list (cons (datum->syntax k) v) ...))
 #'(new button% [k v] ...)]))

; Work, but not my end goal
(mk-widget (list (cons 'label "init")
 (cons 'parent frame)
 (cons 'stretchable-width #t)))

; My end goal
; (define d (list (cons 'label "init") (cons 'parent frame)))
; (mk-widget d)


It works in the first case because I think that the variable is never
created.
My goal is the second case, where it is given by a variable. But I hope
this can help a little. Is there a way to have a `list->syntax`?

Thank you for reading,
Denis

Denis Michiels  writes:

> Hello,
>
> thank you for this start of response, but my goal is to be more general,
> and not to make specific action (here, the label must be the first in
> the list, ...).
>
> In fact, I want to "rewrite" the `new` function, but only with raw
> data-type (like list and cons). Or at least, something that transform
> raw data-type to the `new` function.
>
> And I hope it could be used for any class (at least for GUI class). Is
> that possible or I'm trying to do something that is not the goal of
> macro in Racket?
>
> kind regards,
> Denis
>
>
> Matthias Felleisen  writes:
>
>>> On May 14, 2018, at 6:55 AM, Denis Michiels  wrote:
>>> 
>>> Hello,
>>> 
>>> I'm trying to build a macro to be able to do :
>>> 
>>> ```
>>> (define data (list (cons 'label "My button")
>>>   (cons 'stretchable-width #t)))
>>> 
>>> (my-macro button% data)
>>> ```
>>> 
>>> to be translated in  :
>>> 
>>> ```
>>> (new button% [label "My button"] [stretchable-width #t])
>>> ```
>>> 
>>> (I take gui example, and incomplete (like no frame) but it is to show my
>>> goal)
>>> 
>>> Unfortunately, I didn't manage well macro in Racket...
>>> Can someone help me, or have a hint how to manage this macro?
>>>  
>>
>> #lang racket/gui
>>
>> (define data '((label "My button") (stretchable-width #t)))
>>
>> (define-syntax (mk-but stx)
>>   (syntax-case stx ()
>> [(_ data)
>>  #'(let ()
>>  (match-define (cons label others) data)
>>  (define button (make-object button% (second label) frame))
>>  (for ((o others))
>>(match-define (list m val) o)
>>(dynamic-send button m val)))]))
>>
>>
>> (define frame (new frame% [label "test"]))
>>
>> (mk-but data)
>>
>> (send frame show #t)

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


Re: [racket-users] Macro from list to class init

2018-05-15 Thread Denis Michiels
Hello,

thank you for this start of response, but my goal is to be more general,
and not to make specific action (here, the label must be the first in
the list, ...).

In fact, I want to "rewrite" the `new` function, but only with raw
data-type (like list and cons). Or at least, something that transform
raw data-type to the `new` function.

And I hope it could be used for any class (at least for GUI class). Is
that possible or I'm trying to do something that is not the goal of
macro in Racket?

kind regards,
Denis


Matthias Felleisen  writes:

>> On May 14, 2018, at 6:55 AM, Denis Michiels  wrote:
>> 
>> Hello,
>> 
>> I'm trying to build a macro to be able to do :
>> 
>> ```
>> (define data (list (cons 'label "My button")
>>   (cons 'stretchable-width #t)))
>> 
>> (my-macro button% data)
>> ```
>> 
>> to be translated in  :
>> 
>> ```
>> (new button% [label "My button"] [stretchable-width #t])
>> ```
>> 
>> (I take gui example, and incomplete (like no frame) but it is to show my
>> goal)
>> 
>> Unfortunately, I didn't manage well macro in Racket...
>> Can someone help me, or have a hint how to manage this macro?
>>  
>
> #lang racket/gui
>
> (define data '((label "My button") (stretchable-width #t)))
>
> (define-syntax (mk-but stx)
>   (syntax-case stx ()
> [(_ data)
>  #'(let ()
>  (match-define (cons label others) data)
>  (define button (make-object button% (second label) frame))
>  (for ((o others))
>(match-define (list m val) o)
>(dynamic-send button m val)))]))
>
>
> (define frame (new frame% [label "test"]))
>
> (mk-but data)
>
> (send frame show #t)

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