Re: [racket-users] Simple macro issues

2019-09-08 Thread Simon Haines
Thanks Sorawee,

So what is 'num' inside define-syntax-rule if not a syntax object? And why 
did my earlier attempt create a macro that tried to evaluate its arguments? 
In other words, what are the steps I need to take, or the realisations I 
need to make, to work back from "a: unbound identifier in: a" to a solution 
like you provided? Thanks again.


On Monday, 9 September 2019 15:31:29 UTC+10, Sorawee Porncharoenwase wrote:
>
> This works for me:
>
> #lang racket
>
> (define (hex:char x)
>   (if (number? x)
>   x
>   (string->number (symbol->string x) 16)))
>
> (define-syntax-rule (hex num ...) (bytes (hex:char (quote num)) ...))
>
> (hex a b c 1 2 3) ; #"\n\v\f\1\2\3"
>
> It’s almost always a mistake to use a function that manipulate syntax 
> object (syntax-e, etc.) inside syntax-rules, because syntax-rules don’t 
> give you an access to the syntax object. If you do want to manipulate 
> syntax object, use syntax-cases instead. In your case, however, the 
> problem is easy enough that you don’t need to directly manipulate syntax 
> objects.
>
> On Mon, Sep 9, 2019 at 12:12 PM Simon Haines  > wrote:
>
>> I'm trying to write a macro that will turn a list of hex literals into a 
>> byte string.
>>
>> (hex a b c 1 2 3) ; #"\n\v\f\1\2\3"
>>
>> After many hours I have finally come up with this:
>>
>> #lang racket
>> (define-syntax hex
>>   (syntax-rules ()
>> [(_ num ...)
>>  (bytes
>>   (let ([e (syntax-e #'num)])
>> (if (number? e) num
>> (string->number (symbol->string e) 16))) ...)]))
>>
>> (hex a b c 1 2 3)
>>
>> Of course there are many issues with checking the parameters etc. My 
>> problem is this generates "a: unbound identifier in: a" because the 
>> arguments are evaluated? If I remove the last line it works in the REPL OK.
>>
>> I suspect this is a small matter of my phases being mixed up, or a 
>> misunderstanding of when macros can be defined and used, or just outright 
>> ignorance on my part. I couldn't find any clues in the many, many 
>> references and tutorials I have read. I want to master them but I loathe 
>> creating macros, they always make me feel like an idiot, and I hope Racket2 
>> simplifies them somehow.
>>
>> Thanks for any help sorting this one out.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/6d096642-b770-4655-acc5-08b36e176554%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/7cde7865-4247-4abc-87b7-7f2b561cf210%40googlegroups.com.


Re: [racket-users] Simple macro issues

2019-09-08 Thread Sorawee Porncharoenwase
This works for me:

#lang racket

(define (hex:char x)
  (if (number? x)
  x
  (string->number (symbol->string x) 16)))

(define-syntax-rule (hex num ...) (bytes (hex:char (quote num)) ...))

(hex a b c 1 2 3) ; #"\n\v\f\1\2\3"

It’s almost always a mistake to use a function that manipulate syntax
object (syntax-e, etc.) inside syntax-rules, because syntax-rules don’t
give you an access to the syntax object. If you do want to manipulate
syntax object, use syntax-cases instead. In your case, however, the problem
is easy enough that you don’t need to directly manipulate syntax objects.

On Mon, Sep 9, 2019 at 12:12 PM Simon Haines <
simon.hai...@con-amalgamate.net> wrote:

> I'm trying to write a macro that will turn a list of hex literals into a
> byte string.
>
> (hex a b c 1 2 3) ; #"\n\v\f\1\2\3"
>
> After many hours I have finally come up with this:
>
> #lang racket
> (define-syntax hex
>   (syntax-rules ()
> [(_ num ...)
>  (bytes
>   (let ([e (syntax-e #'num)])
> (if (number? e) num
> (string->number (symbol->string e) 16))) ...)]))
>
> (hex a b c 1 2 3)
>
> Of course there are many issues with checking the parameters etc. My
> problem is this generates "a: unbound identifier in: a" because the
> arguments are evaluated? If I remove the last line it works in the REPL OK.
>
> I suspect this is a small matter of my phases being mixed up, or a
> misunderstanding of when macros can be defined and used, or just outright
> ignorance on my part. I couldn't find any clues in the many, many
> references and tutorials I have read. I want to master them but I loathe
> creating macros, they always make me feel like an idiot, and I hope Racket2
> simplifies them somehow.
>
> Thanks for any help sorting this one out.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/6d096642-b770-4655-acc5-08b36e176554%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CADcuegveXyuSWqSts8Bk4D74aOaW-_BbJdV_q89Z5LNoG%2BGR9w%40mail.gmail.com.


[racket-users] Simple macro issues

2019-09-08 Thread Simon Haines
I'm trying to write a macro that will turn a list of hex literals into a 
byte string.

(hex a b c 1 2 3) ; #"\n\v\f\1\2\3"

After many hours I have finally come up with this:

#lang racket
(define-syntax hex
  (syntax-rules ()
[(_ num ...)
 (bytes
  (let ([e (syntax-e #'num)])
(if (number? e) num
(string->number (symbol->string e) 16))) ...)]))

(hex a b c 1 2 3)

Of course there are many issues with checking the parameters etc. My 
problem is this generates "a: unbound identifier in: a" because the 
arguments are evaluated? If I remove the last line it works in the REPL OK.

I suspect this is a small matter of my phases being mixed up, or a 
misunderstanding of when macros can be defined and used, or just outright 
ignorance on my part. I couldn't find any clues in the many, many 
references and tutorials I have read. I want to master them but I loathe 
creating macros, they always make me feel like an idiot, and I hope Racket2 
simplifies them somehow.

Thanks for any help sorting this one out.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/6d096642-b770-4655-acc5-08b36e176554%40googlegroups.com.


Re: [racket-users] Applicable sets and hashes?

2019-09-08 Thread Maciek Godek
Great, thanks!

W dniu niedziela, 8 września 2019 11:57:47 UTC+2 użytkownik ricardo.g.herdt 
napisał:
>
> Hi Maciek, 
>
> yes, it is. Take a look at rackjure: 
>
> https://docs.racket-lang.org/rackjure/index.html#(part._dict-app) 
>
> Regards, 
>
> Ricardo 
>
>
> Am 08.09.2019 11:51 schrieb Maciek Godek: 
> > Hi, 
> > is it possible to take Racket's hash tables and sets, and make them 
> > applicable (like in Clojure)? 
> > 
> > So that, for example 
> > 
> > (#hash((a . 1) (b . 2)) 'a) 
> > 
> > would be equivalent to 
> > 
> > (hash-ref #hash((a . 1) (b . 2)) 'a) 
> > 
> > and 
> > 
> > ((set 1 2 3) 1) 
> > 
> > would be equivalent to 
> > 
> > (set-member? (set 1 2 3) 1) 
> > 
> >  -- 
> >  You received this message because you are subscribed to the Google 
> > Groups "Racket Users" group. 
> >  To unsubscribe from this group and stop receiving emails from it, 
> > send an email to racket...@googlegroups.com . 
> >  To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/racket-users/879ae299-8f3f-4b9a-b13e-16727f347cb8%40googlegroups.com
>  
> > [1]. 
> > 
> > 
> > Links: 
> > -- 
> > [1] 
> > 
> https://groups.google.com/d/msgid/racket-users/879ae299-8f3f-4b9a-b13e-16727f347cb8%40googlegroups.com?utm_medium=email_source=footer
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/c8780d58-ebdf-458b-a3ab-1f93aea109f1%40googlegroups.com.


RE: [racket-users] transparency of structs?

2019-09-08 Thread jos.koot
Thanks,
make-sibling-inspector does what I want.
Jos

-Mensaje original-
De: Ben Greenman  
Enviado el: 08 September 2019 01:20
Para: jos.k...@gmail.com
CC: Racket Users 
Asunto: Re: [racket-users] transparency of structs?

I see the same results on Racket 7.0 and 6.5, so I don't think anything has 
changed.

Maybe the trouble is that (make-inspector) makes a subinspector of 
(current-inspector), which has the same value for both the main module & the 
submodules.

Switching to (make-sibling-inspector) causes (struct? an-s) to return #f


This email has been scanned by BullGuard antivirus protection.
For more info visit www.bullguard.com


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/01d56641%24fbdbc890%24f39359b0%24%40gmail.com.


[racket-users] On multilanguage programming

2019-09-08 Thread Hendrik Boom
I found an interesting document on the STEPS project, presenting the 
astonishing benefits of clever design and the use and improvisation of many, 
many programming languages in one project.

http://www.vpri.org/pdf/tr2012001_steps.pdf

-- hendrik

(found in a document list http://vpri.org/writings.php
which probably lists many other documents of interest)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20190908122205.532d7uracgvsh6fq%40topoi.pooq.com.


Re: [racket-users] Applicable sets and hashes?

2019-09-08 Thread Ricardo Herdt

Hi Maciek,

yes, it is. Take a look at rackjure:

https://docs.racket-lang.org/rackjure/index.html#(part._dict-app)

Regards,

Ricardo


Am 08.09.2019 11:51 schrieb Maciek Godek:

Hi,
is it possible to take Racket's hash tables and sets, and make them
applicable (like in Clojure)?

So that, for example

(#hash((a . 1) (b . 2)) 'a)

would be equivalent to

(hash-ref #hash((a . 1) (b . 2)) 'a)

and

((set 1 2 3) 1)

would be equivalent to

(set-member? (set 1 2 3) 1)

 --
 You received this message because you are subscribed to the Google
Groups "Racket Users" group.
 To unsubscribe from this group and stop receiving emails from it,
send an email to racket-users+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/879ae299-8f3f-4b9a-b13e-16727f347cb8%40googlegroups.com
[1].


Links:
--
[1]
https://groups.google.com/d/msgid/racket-users/879ae299-8f3f-4b9a-b13e-16727f347cb8%40googlegroups.com?utm_medium=email_source=footer


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/ec470a8c6b41ff7d69d16c38877c591d%40posteo.de.


[racket-users] Applicable sets and hashes?

2019-09-08 Thread Maciek Godek
Hi,
is it possible to take Racket's hash tables and sets, and make them 
applicable (like in Clojure)?

So that, for example

(#hash((a . 1) (b . 2)) 'a)

would be equivalent to

(hash-ref #hash((a . 1) (b . 2)) 'a)

and 

((set 1 2 3) 1)

would be equivalent to

(set-member? (set 1 2 3) 1)


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/879ae299-8f3f-4b9a-b13e-16727f347cb8%40googlegroups.com.


Re: [racket-users] [OT] Cities and GPS

2019-09-08 Thread Laurent
This DB is even better:
http://download.geonames.org/export/


On Sun, Sep 8, 2019 at 8:34 AM Laurent  wrote:

> Nice :)
>
>
> On Sat, Sep 7, 2019 at 2:00 AM Alex Harsanyi 
> wrote:
>
>> In fact, I updated the data frame package to be able to read the CSV file
>> directly, without having to process it, so the example now becomes:
>>
>> #lang racket
>> (require data-frame)
>>
>> (define df (df-read/csv "worldcities.csv" #:quoted-numbers? #t))
>>
>> (define ((is-city? name) v)
>>   (equal? (vector-ref v 0) name))
>>
>> (df-select* df "city" "country" "lat" "lng" #:filter (is-city? "Perth"))
>>
>> ;; Produces:
>>
>> ;; '#(#("Perth" "Australia" -31.955 115.84)
>> ;;  #("Perth" "United Kingdom" 56.4003 -3.47))
>>
>> Alex.
>>
>>
>> On Saturday, September 7, 2019 at 8:13:28 AM UTC+8, Alex Harsanyi wrote:
>>>
>>>
>>> That database is simple enough to use directly, not sure if it needs a
>>> separate package:
>>>
>>> #lang racket
>>> (require data-frame)
>>>
>>> ;; The worldcities.csv file has all values quoted, so df-read/csv reads
>>> them
>>> ;; all as strings.  Convert a series to numbers.
>>> (define (->numeric df series)
>>>   (df-add-derived df series (list series) (lambda (v) (string->number (car
>>> v)
>>>
>>> (define df (df-read/csv "worldcities.csv"))
>>>
>>>   ;; Convert numeric series to numbers
>>> (for ([series '("lat" "lng" "population")])
>>>   (->numeric df series))
>>>
>>> (define ((is-city? name) v)
>>>   (equal? (vector-ref v 0) name))
>>>
>>> (df-select* df "city" "country" "lat" "lng" #:filter (is-city? "Perth"))
>>>
>>> ;; The above call produces:
>>>
>>> ;; '#(#("Perth" "Australia" -31.955 115.84)
>>> ;;#("Perth" "United Kingdom" 56.4003 -3.47))
>>>
>>>
>>>
>>> Alex.
>>>
>>> On Friday, September 6, 2019 at 8:37:59 PM UTC+8, Laurent wrote:

 There's a small free database here too:
 https://simplemaps.com/data/world-cities

 I started writing a simple query system for it this morning (csv->rktd,
 then just list of assoc operations).

 On Fri, Sep 6, 2019 at 1:35 PM Sage Gerard 
 wrote:

> Would geonames help?
> http://www.geonames.org/
>
>
>  Original Message 
> On Sep 6, 2019, 8:28 AM, Hendrik Boom < hen...@topoi.pooq.com> wrote:
>
>
> On Thu, Sep 05, 2019 at 10:42:01PM -0700, Alex Harsanyi wrote:
> ...
> >
> > >
> > > A package containing a database of the positions of the major
> cities and
> > > countries would be nice too :)
> > >
> >
> >
> > A general facility able to resolve location names to GPS coordinates
> would
> > be a lot of work, and I don't have time for such a thing. Sorry.
>
> There must be a GPS database of cities available somewhere already.
>
> -- hendrik
>
> --
> You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to racket...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/20190906122801.w5yhwfbzkods2fqr%40topoi.pooq.com.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to racket...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/yGI9c5OlIwdUQNOQy4KIEMKSfaYia4pr4LkSRukDwvb1sTFJfIQ1As6ca3i8jKqz42EV74CWvr4wdmfhQIcDtbniv7KDj4PqI0Giw-t9q_c%3D%40sagegerard.com
> 
> .
>
> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/racket-users/d4353473-061d-4651-aedc-425351833968%40googlegroups.com
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABNTSaHeZf9Su-VDBhW3wsPQfEborx6op43TKnXQi71mOVEdBg%40mail.gmail.com.


Re: [racket-users] [OT] Cities and GPS

2019-09-08 Thread Laurent
Nice :)


On Sat, Sep 7, 2019 at 2:00 AM Alex Harsanyi  wrote:

> In fact, I updated the data frame package to be able to read the CSV file
> directly, without having to process it, so the example now becomes:
>
> #lang racket
> (require data-frame)
>
> (define df (df-read/csv "worldcities.csv" #:quoted-numbers? #t))
>
> (define ((is-city? name) v)
>   (equal? (vector-ref v 0) name))
>
> (df-select* df "city" "country" "lat" "lng" #:filter (is-city? "Perth"))
>
> ;; Produces:
>
> ;; '#(#("Perth" "Australia" -31.955 115.84)
> ;;  #("Perth" "United Kingdom" 56.4003 -3.47))
>
> Alex.
>
>
> On Saturday, September 7, 2019 at 8:13:28 AM UTC+8, Alex Harsanyi wrote:
>>
>>
>> That database is simple enough to use directly, not sure if it needs a
>> separate package:
>>
>> #lang racket
>> (require data-frame)
>>
>> ;; The worldcities.csv file has all values quoted, so df-read/csv reads
>> them
>> ;; all as strings.  Convert a series to numbers.
>> (define (->numeric df series)
>>   (df-add-derived df series (list series) (lambda (v) (string->number (car
>> v)
>>
>> (define df (df-read/csv "worldcities.csv"))
>>
>>   ;; Convert numeric series to numbers
>> (for ([series '("lat" "lng" "population")])
>>   (->numeric df series))
>>
>> (define ((is-city? name) v)
>>   (equal? (vector-ref v 0) name))
>>
>> (df-select* df "city" "country" "lat" "lng" #:filter (is-city? "Perth"))
>>
>> ;; The above call produces:
>>
>> ;; '#(#("Perth" "Australia" -31.955 115.84)
>> ;;#("Perth" "United Kingdom" 56.4003 -3.47))
>>
>>
>>
>> Alex.
>>
>> On Friday, September 6, 2019 at 8:37:59 PM UTC+8, Laurent wrote:
>>>
>>> There's a small free database here too:
>>> https://simplemaps.com/data/world-cities
>>>
>>> I started writing a simple query system for it this morning (csv->rktd,
>>> then just list of assoc operations).
>>>
>>> On Fri, Sep 6, 2019 at 1:35 PM Sage Gerard  wrote:
>>>
 Would geonames help?
 http://www.geonames.org/


  Original Message 
 On Sep 6, 2019, 8:28 AM, Hendrik Boom < hen...@topoi.pooq.com> wrote:


 On Thu, Sep 05, 2019 at 10:42:01PM -0700, Alex Harsanyi wrote:
 ...
 >
 > >
 > > A package containing a database of the positions of the major
 cities and
 > > countries would be nice too :)
 > >
 >
 >
 > A general facility able to resolve location names to GPS coordinates
 would
 > be a lot of work, and I don't have time for such a thing. Sorry.

 There must be a GPS database of cities available somewhere already.

 -- hendrik

 --
 You received this message because you are subscribed to the Google
 Groups "Racket Users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to racket...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/racket-users/20190906122801.w5yhwfbzkods2fqr%40topoi.pooq.com.

 --
 You received this message because you are subscribed to the Google
 Groups "Racket Users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to racket...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/racket-users/yGI9c5OlIwdUQNOQy4KIEMKSfaYia4pr4LkSRukDwvb1sTFJfIQ1As6ca3i8jKqz42EV74CWvr4wdmfhQIcDtbniv7KDj4PqI0Giw-t9q_c%3D%40sagegerard.com
 
 .

 --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/d4353473-061d-4651-aedc-425351833968%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABNTSaHJ%3DRWdnNqxrPG%2B-1vmm74%3DoxQxHXjwH--j%3D%3D673TWcaA%40mail.gmail.com.