[racket-users] Making a text editor

2016-01-31 Thread Kevin Forchione
Hi guys,
I’ve been perusing the documentation on Racket GUI and am interested in making 
a text editor. Is there any source code to model from? The documentation got me 
started, but there are features such as indenting, line numbering and 
keybindings that I’m interested in implementing. I’ve done a bit of searching 
online and see that we’ve got examples using the 2htdp packets and a VI 
graphical editor, but nothing that quite fits the bill for what I’m doing. 

Any pointers are appreciated!

-Kevin

-- 
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] Macro calling macro question

2016-05-20 Thread Kevin Forchione
Hi guys,
I’ve been interested in having a macro build a series of defines. So I decided 
to start small, trying to get to a macro that would do something like the 
following to begin with:

>(foo 3)
(define foo1 1)
(define foo2 2)
(define foo3 3)

I start with a macro that appears to do a single define:

(require (for-syntax racket/syntax))

(define-syntax (_foo stx)
  (syntax-case stx ()
[(_ n) (with-syntax ([id (format-id stx "foo~a" (syntax-e #'n))])
 #'(define id n))]))


And this appears to work for (_foo 3) for instance.

Then I create a macro that calls this macro:

(define-syntax (foo stx)
  (syntax-case stx ()
[(foo n0) #'(_foo n0)]
[(foo n0 n ...) #'(begin
  (_foo n0)
  (foo n ...))]))

thinking that I could do something like (foo 1 2 3) as an intermediary step.  
So I test it with (foo 3) for instance, expecting it to define foo3 and the 
macro debugger tells me that it’s created (define foo3 3), but that foo3 is 
bound as foo3.0, which is a mystery to me as I thought building the id using 
with-syntax and format-id  would have sorted the binding for this.

Looks like I’m at a learning moment…. any explanation why executing (_foo 3) at 
the real works and (foo 3) does not?

Thanks!
-Kevin

-- 
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 calling macro question

2016-05-20 Thread Kevin Forchione
Both techniques worked for me! Thanks! 

I’m not sure why (format-id #’n “foo~a” [syntax-e #’n)) works when (format-id 
six “foo~a” (syntax-e #’n)) does not though. Apparently I need to look into the 
differences between the two contexts.

-Kevin

> On May 20, 2016, at 2:58 PM, Sam Caldwell <s...@ccs.neu.edu> wrote:
> 
> Kevin,
> 
> I have made this exact mistake in the past. The trouble is with the
> lexical context being passed to `format-id`.
> 
> (_foo 3)
> foo3
> ;; 3
> 
> Here, _foo is passed the syntax #'(_foo 3), which came from the same
> environment as the reference, foo3.
> 
> (foo 3)
> foo3
> ;; error ...
> 
> Here, _foo is passed the syntax #'(_foo 3), which was created *by the
> foo macro*, in a different context to the foo3 reference.
> 
> The solution is to pass #'n as the first argument to format-id.
> Hopefully this explanation made some sense.
> 
> - Sam
> 
> On Fri, May 20, 2016 at 5:36 PM, Kevin Forchione <lyss...@gmail.com 
> <mailto:lyss...@gmail.com>> wrote:
> Hi guys,
> I’ve been interested in having a macro build a series of defines. So I 
> decided to start small, trying to get to a macro that would do something like 
> the following to begin with:
> 
> >(foo 3)
> (define foo1 1)
> (define foo2 2)
> (define foo3 3)
> 
> I start with a macro that appears to do a single define:
> 
> (require (for-syntax racket/syntax))
> 
> (define-syntax (_foo stx)
>   (syntax-case stx ()
> [(_ n) (with-syntax ([id (format-id stx "foo~a" (syntax-e #'n))])
>  #'(define id n))]))
> 
> 
> And this appears to work for (_foo 3) for instance.
> 
> Then I create a macro that calls this macro:
> 
> (define-syntax (foo stx)
>   (syntax-case stx ()
> [(foo n0) #'(_foo n0)]
> [(foo n0 n ...) #'(begin
>   (_foo n0)
>   (foo n ...))]))
> 
> thinking that I could do something like (foo 1 2 3) as an intermediary step.  
> So I test it with (foo 3) for instance, expecting it to define foo3 and the 
> macro debugger tells me that it’s created (define foo3 3), but that foo3 is 
> bound as foo3.0, which is a mystery to me as I thought building the id using 
> with-syntax and format-id  would have sorted the binding for this.
> 
> Looks like I’m at a learning moment…. any explanation why executing (_foo 3) 
> at the real works and (foo 3) does not?
> 
> Thanks!
> -Kevin
> 
> --
> 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 
> <mailto:racket-users%2bunsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <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] format-id question

2016-05-09 Thread Kevin Forchione
Hi guys, 
I’ve been working with Racket 6.5 refreshing my macro knowledge and ran into a 
situation with format-id that baffles me. There’s an example of format-id on 
the “Fear of Macros” webpage that puzzles me. 

>(require (for-syntax racket/syntax))
>(define-syntax (hyphen-define/ok3 stx)
(syntax-case stx ()
  [(_ a b (args ...) body0 body ...)
   (with-syntax ([name (format-id stx "~a-~a" #'a #'b)])
 #'(define (name args ...)
 body0 body ...))]))
>(hyphen-define/ok3 bar baz () #t)
>(bar-bas)
#t

So far so good… so I tried a few other arguments:

>(hyphen-define/ok3 bar ? () #t)
>(bar-?)
#t

>(hyphen-define/ok3 bar 7 () #t)
>(bar-7)
 ../../Applications/Racket v6.5/collects/racket/private/map.rkt:26:19: 
format-id: contract violation
  expected: (or/c string? symbol? identifier? keyword? char? number?)
  given: #

That was a surprise. So ids can’t have numerics as part of their arguments in 
format-id? Is that correct? How would I make this work if I wanted to pass 
numbers into the format-id to generate ids like foo7, bar3, etc?

Thanks so much for any insight into this!

-Kevin

-- 
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 gui choice% enabled #f question

2016-05-18 Thread Kevin Forchione
Hi guys, 
What does “enable” do for choice%? I’ve noticed that other wedges prevent 
interaction when enabled #f, but not choice%. Here’s an example:

#lang racket

(require racket/gui)

(define frame (new frame%
   [label "Testing"]
   [x 0]
   [y 0]
   [width 300]
   [height 300]))
(new choice%
 [parent frame]
 [choices (list "A" "B" "C")]
 [label "choose one..."]
 [enabled #f]
 [callback (λ (w e) (printf "selected: ~a~%" (send w get-selection)))])
(send frame show #t)

Is this how it’s supposed to behave? How do I prevent interaction with this 
widget in that case?

Thanks!

-Kevin

-- 
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] Datalog Question

2018-01-31 Thread Kevin Forchione
Can anyone tell me how I would use the datalog = and != tokens? The 
documentation says they can separate terms, such as  != . In the 
program below, how would I create a query for foo(x, ?) where ? is not 3?

#lang datalog

foo(bil, 1).
foo(bob, 3).
foo(joe, 2).

I imagine I’d have to create a rule of some sort. 

-Kevin

-- 
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] Apparent Datalog error?

2018-01-31 Thread Kevin Forchione
Walking through the datalog  tutorial I got the following transcript:

Welcome to DrRacket, version 6.12 [3m].
Language: datalog, with debugging; memory limit: 512 MB.
> parent(john, douglas).
> parent(john, douglas)?
parent(john, douglas).
> parent(john, evlyn)?

> parent(bob, john).
> parent(A, B)?
parent(john, douglas).
parent(bob, john).
> parent(ebbon, bob).
> parent(john, B)?
parent(john, douglas).
> parent(A, A)?

> ancestor(A, B) :- parent(A, B).
> ancestor(A, B) :-
parent(A, C),
parent(C, B).
> ancestor(A, B)?
ancestor(ebbon, bob).
ancestor(bob, john).
ancestor(john, douglas).
ancestor(bob, douglas).
ancestor(ebbon, john).
> 

It seems that the correct answer should also include ancestor(ebbon, douglas). 
Am I doing something wrong?

-Kevin


-- 
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] Testing & global variables

2018-08-07 Thread Kevin Forchione
I’ve got a library that takes  maintains global variables. I’d like to be able 
to test different test files that require this library, but of course if I 
require those files into a single test file for testing various combinations of 
data it corrupts the global variables, which are only valid for a single 
instance of test file. 

Conceptually it looks like:

Library-File
global a
library-functions
Test-file-1
require Library-file
test-data-file-1
Test-file-2
require Library-file
test-data-file-2
Master-test-file
require Test-file-1 Test-file-2 ;; doesn’t work of course….

Any suggestions are appreciated.

Kevin


-- 
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] Testing & global variables

2018-08-07 Thread Kevin Forchione



> On Aug 7, 2018, at 10:56 AM, Alexis King  wrote:
> 
> I guess I’ll take the bait and give the obvious-but-unhelpful answer,
> “Don’t use global variables.” :)
> 
> I’m joking, but only just barely. It seems difficult to give concrete
> advice without knowing more details about your program and why you felt
> it was necessary to use global mutable state in the first place, so
> absent some reason why you need them, I have to recommend you just
> refactor your code to eliminate the globals. The standard techniques for
> writing testable code in other languages still apply in Racket, most
> notably dependency injection (aka “passing arguments to functions”).
> Racket also provides a few tools of its own for managing that kind of
> dynamic parameterization, such as parameters and units.
> 
> Theoretically, an alternative solution would be to create a separate
> namespace (via racket/sandbox or otherwise) for each test file, allowing
> each test to use its own instantiation of the library. This almost
> certainly isn’t what you actually want, though, since real (non-test)
> clients of your library will bump into the same problem, and expecting
> them to do the same workaround is unreasonable. Indeed, I think the
> difficulty of testing an API like this means the the test suite is doing
> what it probably should: hinting that your API is hard to work with and
> needs to be changed.
> 
> Alexis


Here’s a more concrete example: 

Test-file-1
(require library)
(fact foo 10)
(fact bar 30)
(ans (? 30)) 

So the program collects facts and other prolog-like statement into the global, 
then allows that data to be queried (similar to datalog, although I’m not sure 
of datalog’s internals only its syntax and what it does). I suppose what would 
be interesting would be some way of having the library understand what module 
it is a part of and keep track of its data individually. I could probably do 
that by replacing the globals with a hash table and since fact, and, etc are 
macros I could grab the path /filename from the environment and pass that on to 
the library…. parameters are something I’ve not played around with much, but 
that’s something I’ll look into. 

Kevin

-- 
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] Testing & global variables

2018-08-08 Thread Kevin Forchione



> On Aug 7, 2018, at 10:56 AM, Alexis King  wrote:
> 
> I guess I’ll take the bait and give the obvious-but-unhelpful answer,
> “Don’t use global variables.” :)
> 
> I’m joking, but only just barely. It seems difficult to give concrete
> advice without knowing more details about your program and why you felt
> it was necessary to use global mutable state in the first place, so
> absent some reason why you need them, I have to recommend you just
> refactor your code to eliminate the globals. The standard techniques for
> writing testable code in other languages still apply in Racket, most
> notably dependency injection (aka “passing arguments to functions”).
> Racket also provides a few tools of its own for managing that kind of
> dynamic parameterization, such as parameters and units.
> 
> Theoretically, an alternative solution would be to create a separate
> namespace (via racket/sandbox or otherwise) for each test file, allowing
> each test to use its own instantiation of the library. This almost
> certainly isn’t what you actually want, though, since real (non-test)
> clients of your library will bump into the same problem, and expecting
> them to do the same workaround is unreasonable. Indeed, I think the
> difficulty of testing an API like this means the the test suite is doing
> what it probably should: hinting that your API is hard to work with and
> needs to be changed.
> 
> Alexis

After some preliminary testing it looks like Racket’s parameter is exactly what 
I need! 

Thanks!

Kevin

-- 
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] struct question

2018-03-07 Thread Kevin Forchione
Hi guys,
Can we associate more than 1 generic with a struct? Something like:

(struct foo (..) #:methods gen:bar [] gen:baz [] …)

Thanks,
Kevin

-- 
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] Struct initialization?

2018-03-09 Thread Kevin Forchione
Is it possible to initialize a struct field based on values from previously 
defined fields? Something equivalent to let* where 

>(struct foo (A B C))
>(foo 1 2) would produce (foo 1 2 3) for example?

Thanks!
Kevin

-- 
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] Struct general question

2018-03-26 Thread Kevin Forchione


> On Mar 26, 2018, at 9:36 AM, Jens Axel Søgaard <jensa...@soegaard.net> wrote:
> 
> 2018-03-26 17:58 GMT+02:00 Kevin Forchione <lyss...@gmail.com 
> <mailto:lyss...@gmail.com>>:
> In another thread on structs it was confirmed that structs are in essence a 
> vector with some fancy bindings associated. But there must be more going on, 
> for instance, the definition (struct foo (A B)) creates a function foo that 
> when applied does not print like a vector. Is there any documentation 
> instructs that does into the details of what they are and are doing under the 
> hood?
> 
> FWIW here is my way of implementing structs in JavaScript. I assume the C 
> implementation 
> of structs is similar.
> 
> https://github.com/soegaard/urlang/blob/master/compiler-rjs/runtime.rkt#L1730 
> <https://github.com/soegaard/urlang/blob/master/compiler-rjs/runtime.rkt#L1730>
> 
> The most difficult part to implement is structs with supers.
> 
> The C implementation is here:
> 
> https://github.com/racket/racket/blob/master/racket/src/racket/src/struct.c 
> <https://github.com/racket/racket/blob/master/racket/src/racket/src/struct.c>
> 
> 
> /Jens Axel
> 
Thanks! That’s a fascinating artifact. I hadn’t realized structs went down to C 
code. I’d assumed they were built from Racket vectors, which in  turn were 
built on Racket lists, built on Racket pairs, with pairs maybe in C. LOL. 
Probably not the efficient way to do it, which is why it’s in C? 

Kevin

-- 
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] let-syntax example?

2018-04-03 Thread Kevin Forchione
Hi Guys,
Does anyone have an analogous example for let-syntax to something as simple as 
this?

(let ([a 3]) a)

Something like….

(let-syntax ([a 3]) ….) 

At which point I’m stumped as to what expression in the body would return 3. 
There are no examples in the Reference. 

Thanks!
Kevin

-- 
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] Struct general question

2018-03-26 Thread Kevin Forchione


> On Mar 26, 2018, at 11:03 AM, Eric Griffis  wrote:
> 
> The `struct` form is defined in `struct.rkt` [1]. As you can see, `struct` 
> wraps `define-struct/derived` [2], which uses many things exported from 
> `struct.c` [3]. The "Inside: Racket C API" doc [5] describes some of these 
> functions -- see section 16.
> 
> On the matter of structs being essentially vectors: Again in `struct.c` [3], 
> the C function `scheme_make_struct_instance` (line 2388) instantiates a 
> `Scheme_Structure`, which is declared in `schpriv.h` [4], line 1113. The 
> field values go into a `slots` array, which points directly to the 
> `Scheme_Object`s (i.e. arbitrary Racket values) supplied to 
> `scheme_make_struct_instance`. Assuming Racket vectors are essentially C 
> arrays, Racket structs are like vectors in this way.
> 
> Looking at `Scheme_Struct_Type`, defined just above `Scheme_Structure` in 
> `schpriv.h` [4], it's clear there's nowhere to store field names. We can 
> confirm this by looking at `_make_struct_type` in `struct.c` [3], starting at 
> line 4778, as this is the function used (indirectly) by 
> `define-struct/derived`.
> 
> Eric

Thanks, Eric! So maybe the solution for that would not be rewriting the struct 
definition altogether, but providing that additional information in something 
equivalent to a le over lambda, which would contain that meta information? 

I ran into an issue that felt similar to this when I was trying to pass method 
names around in Racket objects. I’ve no idea, but I would think the “solution” 
to both issues would be similar. Admittedly, I’ve not dug down into either 
structs or objects deep enough. 

Kevin

-- 
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] struct-copy question

2018-03-16 Thread Kevin Forchione
Hi guys, 
I’ve noticed that struct-copy doesn’t appear to work when fields are defined 
with #:auto. So this leads to my question, which may not be answerable since it 
would presumably be used to fix struct-copy, but is there a way to retrieve a 
list of struct fields for a struct? I have a feeling there is some macro work 
going on and that the struct isn’t really “aware” of its field names. If that’s 
the case, wouldn’t it be interesting if the macro included building a function 
that would return these names as a symbols list? :) 

Thanks, 
Kevin

-- 
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] struct-copy question

2018-03-16 Thread Kevin Forchione


> On Mar 16, 2018, at 2:38 PM, Kevin Forchione <lyss...@gmail.com> wrote:
> 
> Hi guys, 
> I’ve noticed that struct-copy doesn’t appear to work when fields are defined 
> with #:auto. So this leads to my question, which may not be answerable since 
> it would presumably be used to fix struct-copy, but is there a way to 
> retrieve a list of struct fields for a struct? I have a feeling there is some 
> macro work going on and that the struct isn’t really “aware” of its field 
> names. If that’s the case, wouldn’t it be interesting if the macro included 
> building a function that would return these names as a symbols list? :) 

Actually, what wold be interesting would be a list of lists, containing the 
getters and setters for the struct. :) 

Kevin

-- 
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] struct-copy question

2018-03-17 Thread Kevin Forchione


> On Mar 17, 2018, at 9:24 AM, Eric Griffis  wrote:
> 
> How about a list of identifiers bound to getters or setters? The 
> `extract-struct-info` procedure in Section 5.7 of the Racket Reference 
> appears to give you that.
> 
> Eric

Souned promising, but  it sounds like you have to roll a struct-info first, 
unless I’ve missed something. I did have some fun exploring 5.2 Creating 
Structure Types (the link to Examples for make-struct-field-accessor & 
make-struct-field-mutaor appear to lead you back to the top of the page, but as 
far as I can tell there are no examples there for those functions…) 

No, what I was hoping for was something you could throw a structure instance at 
and obtains a list of its accessors/mutators so that I could then write a 
generalized version of struct-copy (which appears not to copy a struct that has 
#:auto fields. Placing a struct inside of  a define though gives a pretty quick 
glimpse at the underlying code that the (struct ….) generates, and the mutator 
created by make-struct-type is simply thrown away (when not used by 
make-struct-mutator. I would think that between that (if it could be retained) 
and the struct->list function, which produces an index-ordered list of the 
struct’s values, that you could create a struct-copy that would populate all of 
the fields. Of course, you’d have a mutator out in the wild that could always 
modify the struct… no, you’d have to encapsulate all that into a special 
function foo-copy for struct foo, and pass that out with the mutator safely 
encapsulated in a lambda, I supposed

Kevin

-- 
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] struct-copy question

2018-03-20 Thread Kevin Forchione

Just read your GitHub link and see the problem goes beyond my simple #:auto 
issue. Thanks for that link. I’m pretty green to all the thorny issues when it 
comes to dressing primitive datatypes up in fancy bindings and hope the 
magicians of indirection can somehow pull a rabbit out of the hat on this one 
someday. :) 

Kevin 

-- 
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] struct-copy question

2018-03-20 Thread Kevin Forchione
On Mar 20, 2018, at 9:21 AM, Kevin Forchione <lyss...@gmail.com> wrote:
> 
> 
Sorry, wrong example! 

>(struct fish (color (weight #:auto)) #:transparent)
>(define marlin (fish 'orange-and-white))
>(define dory (struct-copy fish marlin [color 'blue]))

../../Applications/Racket/collects/racket/private/define-struct.rkt:953:29: 
fish: arity mismatch;
 the expected number of arguments does not match the given number
  expected: 1
  given: 2
  arguments...:

Kevin
 

-- 
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] struct-copy question

2018-03-20 Thread Kevin Forchione

On Mar 19, 2018, at 2:35 PM, Alexis King  wrote:
> 
> I’m late to this thread, but perhaps I can clarify some things that I
> don’t think have been made entirely clear.
> 
> First of all, you are absolutely correct that structures, at runtime,
> know nothing whatsoever about field names. At runtime, structures are
> fancy vectors; the names provided for their fields just end up being
> used to generate accessor functions that look up values at the
> appropriate index.
> 
> So how do macros like match and struct-copy know what to do? Well, the
> struct macro creates a transformer binding that holds static information
> about the structure type, including the names of field accessors. As
> Eric already demonstrated, you can access that information using
> syntax-local-value combined with extract-struct-info, but that just
> produces a list containing an assortment of information.
> 
> There is a library that provides a struct-id syntax class that makes it
> easier to consume structure type transformer bindings:
> 
>  
> http://docs.racket-lang.org/syntax-classes/index.html#%28form._%28%28lib._syntax%2Fparse%2Fclass%2Fstruct-id..rkt%29._struct-id%29%29
>  
> 
> 
> It works with syntax/parse, and it defines attributes with names that
> handle the different sorts of things that can be produced by
> extract-struct-info. Disclaimer: I am the author of the library.
> 
> Finally, I am not sure about the particular issue with struct-copy and
> #:auto fields (which sounds fixable), but I think it is worth mentioning
> that struct-copy is irreparably broken and cannot be fixed without
> fundamental changes to Racket’s struct system. Namely, it has the
> “slicing” problem familiar to C++ programmers when using struct
> inheritance, and the way it synthesizes field accessors from the
> provided field names is unhygienic and can be easily thwarted. See this
> GitHub issue for more details:
> 
>  https://github.com/racket/racket/issues/1399 
> 
> 
> Alexis


Thanks, guys! This continues to be a very instructive exploration for me. The 
restructuring of struct (lol) sounds like something for a Racket 2? The issue I 
have with struct-copy is pretty easy to create: 

>(struct fish (color (weight #:auto)) #:transparent)
>(define marlin (fish 'orange-and-white 11))
>(define dory (struct-copy fish marlin [color 'blue]))

 fish: arity mismatch;
 the expected number of arguments does not match the given number
  expected: 1
  given: 2
  arguments…:

Kevin

-- 
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 Users] Macros and literals question

2018-09-15 Thread Kevin Forchione
Hi guys,
Is there a way to define a macro so that an argument will be quoted only when 
it is a symbol? Something like this:

(foo 10) => 10
(foo hello) => ‘hello
(foo (lambda (x) (* 2 x))) => 
etc.

Kevin

-- 
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] [Racket Users] Macros and literals question

2018-09-17 Thread Kevin Forchione


> On Sep 16, 2018, at 10:07 PM, Matthew Butterick  wrote:
> 
> 
>> On Sep 16, 2018, at 2:13 PM, Kevin Forchione > <mailto:lyss...@gmail.com>> wrote:
>> 
>> Thanks! That’s just what I wanted. Is there a way in Racket to determine if 
>> a quoted symbol has an associated procedure? 
> 
> 
> 
> #lang racket
> (require rackunit)
> 
> (define-syntax (bound-to-proc? stx)
>   (syntax-case stx ()
> [(_ 'x)
>  (and (identifier? #'x) (identifier-binding #'x))
>  #'(procedure? x)]
> [_ #'#f]))
> 
> (define bound-to-proc +)
> (define not-bound-to-proc 42)
> 
> (check-true (bound-to-proc? 'bound-to-proc))
> (check-false (bound-to-proc? 'not-bound-to-proc))

Sorry for the typo and thanks for the further explanation. Your original 
response to my query was more in line with what I’m trying to accomplish, while 
my second question was more in the realm of  curiosity. In a nutshell I’m 
working with some hash tables whose keys are symbol and whose values may be 
other keys or values such as identifiers, and I got a bit tired of quoting all 
my symbols for functions and decided to use some macros when working with the 
tables. Probably more than curiosity as I can foresee a need to retrieve a 
value from a table and either apply it, which means somehow getting at the 
binding. 

Kevin

-- 
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] [Racket Users] Macros and literals question

2018-09-17 Thread Kevin Forchione


> On Sep 16, 2018, at 10:07 PM, Matthew Butterick  wrote:
> 
> #lang racket
> (require rackunit)
> 
> (define-syntax (bound-to-proc? stx)
>   (syntax-case stx ()
> [(_ 'x)
>  (and (identifier? #'x) (identifier-binding #'x))
>  #'(procedure? x)]
> [_ #'#f]))
> 
> (define bound-to-proc +)
> (define not-bound-to-proc 42)
> 
> (check-true (bound-to-proc? 'bound-to-proc))
> (check-false (bound-to-proc? 'not-bound-to-proc))

Thanks, Matthew. This approach works as long as the macro is being used outside 
of a definition, but I suspect to build any sort of logic around it they’d have 
to be macros as well. For instance, this fails because the macro captures 
symptoms and not the value passed to the function:

[define [foo symbols) (bound-to-proc? sum)) 

That seems to be the nature of macros, and I’m not sure what the solution to 
that paradox is, apart from perhaps building a symbol/function hash table as 
part of a define. Presumably Racke does something like that for eva & 
namespaces, but I’m surprised there isn’t a symbol->procedure function. 

Kevin

-- 
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] [Racket Users] Macros and literals question

2018-09-16 Thread Kevin Forchione


> On Sep 15, 2018, at 7:27 PM, Philip McGrath  wrote:
> 
> Sure. For example:
> 
> #lang racket
> 
> (require syntax/parse/define
>  rackunit)
> 
> (define-syntax-parser foo
>   [(_ arg:id)
>#''arg]
>   [(_ arg:expr)
>#'arg])
> 
> (check-eqv? (foo 10) 10)
> (check-eq? (foo hello) 'hello)
> (check-pred procedure? (foo (λ (x) (* 2 x
> 
> -Philip
> 
> 
> On Sat, Sep 15, 2018 at 9:17 PM Kevin Forchione  <mailto:lyss...@gmail.com>> wrote:
> Hi guys,
> Is there a way to define a macro so that an argument will be quoted only when 
> it is a symbol? Something like this:
> 
> (foo 10) => 10
> (foo hello) => ‘hello
> (foo (lambda (x) (* 2 x))) => 
> etc.

Thanks! That’s just what I wanted. Is there a way in Racket to determine if a 
quoted symbol has an associated procedure? 

Kevin
> 
> -- 
> 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 
> <mailto:racket-users%2bunsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <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] [racket users] Struct property question

2019-03-01 Thread Kevin Forchione
Hi guys, 
I’m trying to understand an example from the Racket manuals. 

(struct mood-procedure (base rating)
  #:property prop:procedure (struct-field-index base))

(define happy+ (mood-procedure add1 10))
 
(happy+ 2) <= 3

How does this work? It appears that prop:procedure is predefined. It appears 
that prop:procedure is assigned the value of whatever is assigned to the base 
slot of the struct, in this case add1. But although mood-procedure is a struct, 
happy+ appears to be a procedure! If I make mood-procedure transparent then 
happy+ looks like this:

(add1 # 10)

I’m not sure how the #:property kw made this transformation, nor what it means 
in terms of the uses of #:property. Any insight is appreciated.

Kevin

-- 
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 help

2019-05-24 Thread Kevin Forchione



> On May 24, 2019, at 7:35 AM, Stephen Chang  wrote:
> 
> If `define-values` is not strictly required, here's a more
> syntax-case-y recursive version:
> 
> (define-syntax (aux stx)
>  (syntax-case stx ()
>[(_) #'(begin)]
>[(_ (var val) . rst)
> (identifier? #'var)
> #'(begin
> (define var val)
> (aux . rst))]
>[(_ var . rst)
> (identifier? #'var)
> #'(begin
> (define var #f)
> (aux . rst))]))
> 
> On Fri, May 24, 2019 at 9:33 AM Matthias Felleisen
>  wrote:
>> 
>> 
>> Let me propose the use of syntax-parse as an alternative here. I think it 
>> clarifies the purpose of the maco. — Matthias
>> 
>> 
>> #lang racket
>> 
>> (require (for-syntax syntax/parse))
>> 
>> #; (aux a (b (* 2 pi)) c (d pi))
>> ;; =>
>> #; (define-values (a b c d) (values #f 6.28318530717958 #f 
>> 3.141592653589793))
>> 
>> 
>> (begin-for-syntax
>>  (define-syntax-class optionally-initiliazed
>>(pattern (lhs:id rhs:expr))
>>(pattern lhs:id #:attr rhs #'#f)))
>> 
>> (define-syntax (aux stx)
>>  (syntax-parse stx
>>[(_ p:optionally-initiliazed ...) #'(define-values (p.lhs ...) (values 
>> p.rhs ...))]))
>> 
>> (aux a (b (* 2 pi)) c (d pi))
>> 
>> 
>> 
>> 
>> On May 24, 2019, at 12:52 AM, Michael Murdock MacLeod 
>>  wrote:
>> 
>> Does this work? It uses a helper function, `prune`, to parse the var-val
>> clauses.
>> 
>> #lang racket
>> 
>> (define-for-syntax (prune stx)
>> (syntax-case stx ()
>>   [()
>>#'()]
>>   [((var val) others ...)
>>(cons #'(var val)
>>  (prune #'(others ...)))]
>>   [(var others ...)
>>(cons #'(var #f)
>>  (prune #'(others ...)))]))
>> 
>> (define-syntax (aux stx)
>> (syntax-case stx ()
>>   [(_ terms ...)
>>(with-syntax ([((var val) ...) (prune #'(terms ...))])
>>  #'(define-values (var ...) (values val ...)))]))
>> 
>> (aux a (b (* 2 pi)) c (d pi))
>> a
>> b
>> c
>> d
>> 
>> ;; output shown below
>> 
>> #f
>> 6.283185307179586
>> #f
>> 3.141592653589793

Wow! Thanks so much guys. Each of these solutions adds another brick to the 
wall of my macro eduction!

Kevin

-- 
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/88FB1562-1F78-434E-8D6A-78DE8D86C909%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-02 Thread Kevin Forchione


> On Jun 2, 2019, at 7:13 PM, Matthias Felleisen  wrote:
> 
> 
> 
>> On Jun 2, 2019, at 9:41 PM, Kevin Forchione > <mailto:lyss...@gmail.com>> wrote:
>> 
>> Hi guys,
>> I’ve been working with macros and let/cc and have a situation where I have 
>> the 2nd macro bound to the let/cc return of the first. No idea how I’d do 
>> that, but here’s an example of what I’m attempting to do:
>> 
>> #lang racket
>> 
>> (require (for-syntax racket/syntax))
>> 
>> (define-syntax (fn stx)
>>  (syntax-case stx ()
>>[(_ (arg ...) body0 body ...)
>> (with-syntax ([return (format-id #'body0 "~a" #'return)])
>>   #'(λ (arg ...) (let/cc return body0 body ...)))]))
>> 
>> (define-syntax (false stx)
>>  (syntax-case stx ()
>>[(_) #'(return #f)]))
>> 
>> ((fn (x y) (when (< x y) (return x)) y) 2 30) ; => 2
>> ((fn (x y) (when (< x y) (false)) y) 2 30)   ;=> #f
>> 
>> My thought is that the 2nd macro doesn’t know about the 1st macro except 
>> perhaps through the six of compile time… so that if I had define-syntax 
>> working with a lambda I’d have all the pieces available in the (fn …) but 
>> not sure what tools I might use to accomplish that.
>> 
>> Any ideas are appreciated!
>  
> 
> This situation calls for syntax-parameters in my mind: see docs, too — 
> Matthias

Hmmm. A cursory glance at some of the examples suggests I’ll have to do some 
exploring on this. One issue that it looks like I’ll have to work out is that 
“false” in my example needs to translate to “(return #f)” and I’m not sure at 
this stage where a syntax-parameterize statement would be positioned in the fn 
macro (or how it would know to use it unless it could interrogate the body list 
looking for that value. That might be what I’d need to do here…

Kevin

-- 
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/C4425B12-9C1F-4159-B4BA-D09C89419CB9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] macros and let/cc

2019-06-02 Thread Kevin Forchione
Hi guys,
I’ve been working with macros and let/cc and have a situation where I have the 
2nd macro bound to the let/cc return of the first. No idea how I’d do that, but 
here’s an example of what I’m attempting to do:

#lang racket

(require (for-syntax racket/syntax))

(define-syntax (fn stx)
  (syntax-case stx ()
[(_ (arg ...) body0 body ...)
 (with-syntax ([return (format-id #'body0 "~a" #'return)])
   #'(λ (arg ...) (let/cc return body0 body ...)))]))

(define-syntax (false stx)
  (syntax-case stx ()
[(_) #'(return #f)]))

((fn (x y) (when (< x y) (return x)) y) 2 30) ; => 2
((fn (x y) (when (< x y) (false)) y) 2 30)   ;=> #f

My thought is that the 2nd macro doesn’t know about the 1st macro except 
perhaps through the six of compile time… so that if I had define-syntax working 
with a lambda I’d have all the pieces available in the (fn …) but not sure what 
tools I might use to accomplish that.

Any ideas are appreciated!

Kevin



-- 
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/957E342B-2DCB-4413-9577-8B9F3B1F66BD%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Kevin Forchione


> On Jun 3, 2019, at 4:54 AM, Alex Knauth  wrote:
> 
> 
> 
>> On Jun 3, 2019, at 1:02 AM, Kevin Forchione > <mailto:lyss...@gmail.com>> wrote:
>>> On Jun 2, 2019, at 7:13 PM, Matthias Felleisen >> <mailto:matth...@felleisen.org>> wrote:
>>>> On Jun 2, 2019, at 9:41 PM, Kevin Forchione >>> <mailto:lyss...@gmail.com>> wrote:
>>>> 
>>>> Hi guys,
>>>> I’ve been working with macros and let/cc and have a situation where I have 
>>>> the 2nd macro bound to the let/cc return of the first. No idea how I’d do 
>>>> that, but here’s an example of what I’m attempting to do:
>>>> 
>>>> #lang racket
>>>> 
>>>> (require (for-syntax racket/syntax))
>>>> 
>>>> (define-syntax (fn stx)
>>>>  (syntax-case stx ()
>>>>[(_ (arg ...) body0 body ...)
>>>> (with-syntax ([return (format-id #'body0 "~a" #'return)])
>>>>   #'(λ (arg ...) (let/cc return body0 body ...)))]))
>>>> 
>>>> (define-syntax (false stx)
>>>>  (syntax-case stx ()
>>>>[(_) #'(return #f)]))
>>>> 
>>>> ((fn (x y) (when (< x y) (return x)) y) 2 30) ; => 2
>>>> ((fn (x y) (when (< x y) (false)) y) 2 30)   ;=> #f
>>>> 
>>>> My thought is that the 2nd macro doesn’t know about the 1st macro except 
>>>> perhaps through the six of compile time… so that if I had define-syntax 
>>>> working with a lambda I’d have all the pieces available in the (fn …) but 
>>>> not sure what tools I might use to accomplish that.
>>>> 
>>>> Any ideas are appreciated!
>>> 
>>> This situation calls for syntax-parameters in my mind: see docs, too — 
>>> Matthias
>> 
>> Hmmm. A cursory glance at some of the examples suggests I’ll have to do some 
>> exploring on this. One issue that it looks like I’ll have to work out is 
>> that “false” in my example needs to translate to “(return #f)” and I’m not 
>> sure at this stage where a syntax-parameterize statement would be positioned 
>> in the fn macro
> 
> It should go around the same set of expressions that the `return` identifier 
> would have been unhygienically bound in. For this example, that means around 
> `body0 body ...`, or in context:
> 
> (λ (arg ...) (let/cc k (syntax-parameterize ([return ( #'k )]) body0 
> body ...)))
> 
>> (or how it would know to use it unless it could interrogate the body list 
>> looking for that value. That might be what I’d need to do here…
> 
> I'm not sure what you mean by interrogate the body, but if you're referring 
> to the syntax-parameterize needing access to the continuation bound by 
> let/cc, then your right. That's why in the example above, the 
> syntax-parameterize needs to be inside of the let/cc where `k` is bound, and 
> the new parameter value needs to refer to `k`. Is that what you meant?

That’s what I was thinking, but the transformation would have to be something 
more like:

(let/cc return
(syntax-parameterize ([false #'(return #f)]) body0 body 
...]))

And that doesn’t work. I imagine that would expand into ((return #f)). 

Kevin

-- 
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/135285AD-843C-4258-8034-EF9F59E27EB0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Macro guards question

2019-05-29 Thread Kevin Forchione
Hi Guys,
What are the rules for macro guards? I’ve only seen examples with (identifier? 
#’val) being used. What about (number? #’val) or (spring? #’val)? When I try 
these I get a foo: bad syntax so I’m suspecting these can’t be used or there’s 
some trick to them. 

What I’ve been trying to create (and maybe this isn’t the right way to go about 
it) is a syntax-case that would have have various type checks as guards and 
then select the branch based on whether I’ve got an identifier or just a 
symbol, or a number or a string, etc. 

(syntax-case six ()
  [(_ arg) (identifier? #’arg) #’(identifier-handler arg)]
  [(_ arg) (symbol? #’arg) #’(symbol-handler arg)]
  [(_ arg) (string? #’arg) #’(string-handler arg)]
   …)

That sort of thing. 

Primarily I find myself running into an issue where I’m using symbols for 
lookup keys and identifiers for their reference values  and running into a wall 
of wanting the macro to go ahead and handle them differently without have the 
old “foo undefined” popping up. :) 

Kevin

-- 
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/DED7E28E-9B3D-4045-B0DC-CBD3AB11E653%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Kevin Forchione



> On Jun 3, 2019, at 8:51 AM, Matthias Felleisen  wrote:
> 
> 
> My code run your examples. Whay is missinng? 
> 
Here’s what I’ve been trying to run.

#lang racket

(require (for-syntax racket/syntax)
 racket/stxparam)

(define-syntax-parameter false
  (lambda (stx)
  (raise-syntax-error (syntax-e stx) "can only be used inside lambda.")))

(define-syntax (fn stx)
  (syntax-case stx ()
[(_ (arg ...) body0 body ...)
 (with-syntax ([return (format-id #'body0 "~a" #'return)])
   #'(λ (arg ...) (let/cc return
(syntax-parameterize ([false #'return]) body0 body 
...]))

((fn (x y) (when (< x y) (return x)) y) 2 30) ; => 2
((fn (x y) (when (< x y) (false)) y) 2 30)


Kevin

-- 
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/CC4AB8E6-76E4-43C3-9D2D-497F7467B858%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Kevin Forchione



> On Jun 3, 2019, at 9:09 AM, Matthias Felleisen  wrote:
> 
> 
> Or, 
> 
> #lang racket
> 
> (require (for-syntax ) racket/stxparam)
> 
> (define-syntax-parameter return (syntax-rules ()))
> (define-syntax-parameter false (syntax-rules ()))
> 
> (define-syntax fn
> (syntax-rules ()
>   [(_ (arg ...) body ...)
>(λ (arg ...)
>  (let/cc fn-exit
>(syntax-parameterize ([return (syntax-rules () [(_ x) (fn-exit x)])])
>  (syntax-parameterize ([false (syntax-rules () [(_) (return #f)])])
>body ...]))
> 
> ((fn (x y) (when (< x y) (return x)) y) 2 30) ; => 2
> ((fn (x y) (when (< x y) (false)) y) 2 30)   ;=> #f
> 

Oh! I see! That solves the expansio issue! Wonderful. You’ve opened up a whole 
new set of possibilities for me. Thanks, Matthias.

-- 
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/F77FB88D-5D84-4F67-87F5-8F53717DFF61%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macros and let/cc

2019-06-03 Thread Kevin Forchione



> On Jun 3, 2019, at 9:42 AM, Matthias Felleisen  wrote:
> 
> 
> 
>> On Jun 3, 2019, at 12:33 PM, Kevin Forchione  wrote:
>> 
>> Oh! I see! That solves the expansio issue! Wonderful. You’ve opened up a 
>> whole new set of possibilities for me. Thanks, Matthias.
> 
> 
> I am glad I sent my solution a second time :)

Me, too. For some reason the bundling of my emails appeared only to present 
your suggestion of using syntax-parameters and perusing of docs and not the 
code! It made your follow-up comments cryptic though I didn’t realize I was 
missing something until the “OR” in your prior email. Going back through the 
bundle the earlier code was there. The “Or” solution, however, brought home to 
me that you can nest the syntax-parameterize calls. :) 

Kevin

-- 
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/34F49B72-5C89-4994-9288-43DB336E2DBE%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Macro guards question

2019-05-29 Thread Kevin Forchione


> On May 29, 2019, at 11:09 AM, Sorawee Porncharoenwase 
>  wrote:
> 
> (foo a) ;=> 1
> (foo "a") ;=> 2
> (foo 10) ;=> 3
> (foo 'a) ;=> 4
> (foo (bar x)) ;=> 5
Ah… thanks so much for the explanation. That’s put me much closer (I hope!) to 
the solution I’m after. A bit of stumbling around through some documentation 
has got me this far.Being able to handle (foo a) and (foo b) below differently 
is a distinction I’ve been after for a while!

#lang racket

(define-syntax (foo stx)
  (syntax-case stx ()
[(_ arg) (and (identifier? #'arg) (identifier-binding #'arg 0 #t)) #'1]
[(_ arg) (identifier? #'arg) #'2]
[(_ arg) (string? (syntax->datum #'arg)) #'3]
[(_ arg) (number? (syntax->datum #'arg)) #'4]
[(_ (quote* x)) (and (free-identifier=? #'quote* #'quote)
 (symbol? (syntax->datum #'x))) #'5]
[(_ _) #'6]))

(define a #t) ;=> a is top-level bound, b is not.

(foo a)   ;=> 1
(foo b)   ;=> 2
(foo "a") ;=> 3
(foo 10)  ;=> 4
(foo 'a)  ;=> 5
(foo (bar x)) ;=> 6


Kevin

-- 
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/506321EF-0D5B-4551-8671-268E6808B015%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] macro guard question (ellipsis)

2019-06-18 Thread Kevin Forchione
Hi guys,
I’ve been trying to figure out the syntax for a guard when the pattern has 
ellipsis and you want to guard one of the variables. Here’s an uninteresting 
macro but it shows what I mean.

#lang racket

(define-syntax (foo stx)
  (syntax-case stx ()
[(_ (key val ...) ...)
 (and (identifier? #'key) (identifier? #'val))
 #'(quote (list ((quote key) (quote val) ...) ...))]))

(foo (a b) (c d e))

Of course it complains about the ellipsis being missing in the pattern. Is this 
something I can handle with a guard in this manner or do I need a helper macro 
of some sort? 

Thanks!
Kevin


-- 
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/D76D1CBC-BF78-493F-89B9-9498D615A5E7%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] macro guard question (ellipsis)

2019-06-19 Thread Kevin Forchione


> On Jun 18, 2019, at 9:03 PM, Sorawee Porncharoenwase 
>  wrote:
> 
> Also note that with syntax/parse, it becomes much easier:
> 
> (require (for-syntax syntax/parse))
> 
> (define-syntax (foo stx)
>   (syntax-parse stx
> [(_ (key:id val:id ...) ...)
>  #'(quote (list ((quote key) (quote val) ...) ...))]))

Thanks! Looks like it’s finally time for me to do a deep dive into 
syntax-parse. 

Kevin

-- 
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/90AE6155-00A2-42F9-A518-A5114528B151%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] symbols question

2019-06-20 Thread Kevin Forchione
Hi guys,
Every now and then I wonder about the decisions behind the languages we work 
with and of late I’m wondering about symbols. By default symbols reveal their 
binding value unless you explicitly tell them not to — in other words unless 
you quote them. And that’s pretty useful. In macros I can control this behavior 
by taking my symbol and wrapping a quote around it. And I’ve even had some good 
results with guards using identifier-binding to determine whether I need to do 
that or not — though I’m not sure about the limitations and contextual 
restrictions of that approach — there’s nothing that simply says “if this 
symbol is exposed to evaluation it’ll produce a binding exception so we’ll wrap 
it in a quote for you” sort of mechanism that I’m aware of…  at least not one 
that doesn’t require some qualification.And there’s the other approach that I’m 
playing with now as well: wapping symbols in quotes by default unless I 
explicitly state not to — a sort of unquote passed into the macro syntax that 
makes the syntax look a little like MDL, but I haven’t worked out all the kinks 
in that approach yet. And of course sometimes I’d like to just toss symbols 
around without having a bind to worry about — keywords I suppose, but without 
the association to function arguments — just something to compare or key on. I 
suppose there’s probably a way to do this with the reader, though I haven’t 
looked into that much yet. And finally there’s the common lisp itch I get from 
time to time to have symbols with bindings and plist sort of associations — 
parameterized hash tables to store the values perhaps. 

In all this meandering, the question is whether there are libraries doing these 
sorts of things already? It’s fun to re-invent the wheel at times, but also 
instructive to learn while standing on the shoulders of giants, so to speak, 
and creatively stimulating. :) 

Kevin

-- 
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/EB9B5188-4B62-42BB-B24F-2B95166E95F7%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] symbols question

2019-06-21 Thread Kevin Forchione


> On Jun 20, 2019, at 10:18 PM, Sorawee Porncharoenwase 
>  wrote:
> 
> #lang racket
> 
> (require syntax/parse/define)
> 
> (define-simple-macro (#%top . x) 'x)
> 
> (define x 42)
> x ;=> 42
> y ;=> 'y
> (string-length (symbol->string abcdef)) ;=> 6
> Unbound identifiers are wrapped with #%top during expansion steps 
> ,
>  so you can define #%top to deal with unbound ids. For instance, Pollen 
>  by default uses #%top to create default tags 
> .
> 
> Wow! That does appear to be just what I’ve been looking for. 

Thanks so much!  Looks like I’m going to have some fun!

Kevin

-- 
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/D8F840D6-70E6-4A59-A0A2-ECCDCBCF0DEC%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Macro help

2019-05-23 Thread Kevin Forchione
Hi guys,
I’ve been wracking my brains all day trying to come up with a macro that would 
convert this syntax:

;; (aux a (b (* 2 pi)) c (d pi))
;; => (define-values (a b c d) (values #f 6.28318530717958 #f 3.141592653589793)


I’m missing some part of the picture. The closest I’ve come is to create a list 
of the pairs:

#lang racket

(define-syntax (aux stx)
  (syntax-case stx ()
[(_ (var val)) #'`((var ,val))]
[(_ var) #''((var #f))]
[(_ (var0 val0) var1 ...) #'(append `((var0 ,val0)) (aux var1 ...))]
[(_ var0 var1 ...) #'(append '((var0 #f)) (aux var1 ...))]))

(aux a (b (* 2 pi)) c (d pi)) ;=> '((a #f) (b 6.283185307179586) (c #f) (d 
3.141592653589793))


Any help is greatly appreciated!

Kevin

-- 
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/AC605DEF-0AC6-4590-B53F-700C6AE14D4D%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] raise-argument-error missing list?

2019-07-05 Thread Kevin Forchione
Hi guys,
Been adding raise-argument-error to my functions to catch errors and have 
noticed that the 2nd version of the form doesn’t actually list the other 
arguments - even for the example in the docs:

>(define (feed-animals cow sheep goose cat)
(if (not (eq? goose 'goose))
  (raise-argument-error 'feed-animals "'goose" 2 cow sheep goose cat)
  "fed the animals"))
>(feed-animals 'cow 'sheep 'dog ‘cat)

. . feed-animals: contract violation
  expected: 'goose
  given: 'dog
  argument position: 3rd
  other arguments...:
> 

Is this form recommended? I’ve noticed that the documentation says some of the 
error forms have been deprecated. 

-Kevin

-- 
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/91E9AD52-8F17-4BC3-98AB-5E43FFABC9DF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] raise-argument-error missing list?

2019-07-05 Thread Kevin Forchione



> On Jul 5, 2019, at 10:51 AM, Matthew Flatt  wrote:
> 
> DrRacket hides the other arguments to make the error message initially
> more compact. Click "..." in DrRacket to expose the arguments.
> 

Thanks! The explanation has suddenly made it “intuitive” to me :) 

Kevin

-- 
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/58FFC892-D6FD-4927-8ACD-3FF48553A0C2%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Contracts in lambda?

2019-07-11 Thread Kevin Forchione



> On Jul 10, 2019, at 9:14 PM, Matthias Felleisen  
> wrote:
> 
> 
> [(contract (-> string? integer?) (λ (x) x) 'a 'b)
> "hello”]

By the way, I’ve been playing around with this (and define/contract) and it 
seems that ‘a in the above refers to the function itself, while to the best of 
my knowledge ‘b refers to … the module pathname? Is that how this is supposed 
to report?  So in a macro I’d use something like (syntax-source #’#f) to 
retrieve that. But I’m suspicious that that is too simplistic. 

Are my assumptions correct? Not sure how a macro would know more than than the 
defining module, but I’m always being surprised. 

Kevin

-- 
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/B0CC2857-21A7-45C4-AD12-07D2D19710F9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Capturing print?

2019-07-10 Thread Kevin Forchione
Hi guys,
Is there a wrapper or something like that that I can place around a print 
expression so that it captures it and returns a string value? Something like: 

[capture-print [printf “hello, world!”)) => “hello, world!”

There are times when testing I’d like to capture the output and compare it with 
a check-equal? and suppress it from displaying in testing It could also be 
useful in other was possibly for delaying and manipulating printed output. 

Kevin

-- 
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/CC768C18-C600-4136-8EF7-1A4AAC19BA25%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Capturing print?

2019-07-10 Thread Kevin Forchione


> On Jul 10, 2019, at 1:53 PM, bruno cuconato  wrote:
> 
> there's 
> https://docs.racket-lang.org/reference/port-lib.html#%28def._%28%28lib._racket%2Fport..rkt%29._with-output-to-string%29%29
>  
> 
>  and company.
> would that work for you?
> 
> -- bruno cuconato

Thanks! Yes, I think with a little tinkering I can get that to work for what I 
have in mind. Took me awhile to discover *how* that is supposed to work! 
Apparently the proc for with-output-to-string is a thunk:

(with-output-to-string (λ a
 (printf "a=~a~%" a)
 (define x 10)
 (define y 20)
 (printf "x=~a y=~a~%" x y)))

=> "a=()\nx=10 y=20\n”


Something a little macro can handle:

(define-syntax (output->string stx)
  (syntax-parse stx
[(_ body:expr ...) #'(with-output-to-string (thunk body ...))]))

(output->string
(define x 10)
  (define y 20)
  (printf "x=~a y=~a~%" x y))


=> "x=10 y=20\n"


Kevin

-- 
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/5D3552E4-F7E0-4223-8D99-A16C40E30FFE%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Contracts in lambda?

2019-07-10 Thread Kevin Forchione
Hi guys,
Is there a way to apply contracts to a lambda without associating it with an 
identifier? What I want is to be able to pass lambda functions around without 
having to bind them to a symbol. I could use raise-argument-error/ 
raise-result-error but the contract system is more powerful and  I’m hoping 
there’s a wrapperI of some sort that will do the trick. Something like:

(assert-contract [tag] (lambda argspec contract-spec body …)) ;; <= [ta] would 
just be a symbol for the error message 

Kevin

-- 
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/B0725B4A-8D61-4F6C-AE31-9A7E067F82AE%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Contracts in lambda?

2019-07-11 Thread Kevin Forchione



> On Jul 10, 2019, at 9:14 PM, Matthias Felleisen  
> wrote:
> 
> 
> [(contract (-> string? integer?) (λ (x) x) 'a 'b)
> "hello”]
> 


Nice! Thanks!

Kevin

-- 
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/249E62A8-9E54-4BB1-9267-89D39DC172B5%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Contracts in lambda?

2019-07-11 Thread Kevin Forchione



> On Jul 10, 2019, at 9:14 PM, Matthias Felleisen  
> wrote:
> 
> 
> [(contract (-> string? integer?) (λ (x) x) 'a 'b)
> "hello”]

Incidentally, I’m not sure why, it must be something to do with the way I take 
apart and put together the world (i.e. the way I “learn” :) , but until a few 
posts ago I hadn’t grasped that the (->i and (->* notation are applicable the 
various places contracts are used! I’d used them in the provide expression and 
for some reason didn’t  extrapolate beyond it. I had a similar experience with 
syntax parameters and the use of syntax- within syntax-x expressions. 
Very interesting meta-revelation. 

Kevin

-- 
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/AA473B53-7976-430F-B8A3-B1D99DB699FD%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Contracts in lambda?

2019-07-11 Thread Kevin Forchione


> On Jul 11, 2019, at 12:34 PM, Alex Knauth  wrote:
> 
> 
> 
>> On Jul 11, 2019, at 1:15 PM, Kevin Forchione > <mailto:lyss...@gmail.com>> wrote:
>> 
>>> On Jul 10, 2019, at 9:14 PM, Matthias Felleisen >> <mailto:matth...@felleisen.org>> wrote:
>>> 
>>> [(contract (-> string? integer?) (λ (x) x) 'a 'b)
>>> "hello”]
>> 
>> By the way, I’ve been playing around with this (and define/contract) and it 
>> seems that ‘a in the above refers to the function itself, while to the best 
>> of my knowledge ‘b refers to … the module pathname? Is that how this is 
>> supposed to report?  So in a macro I’d use something like (syntax-source 
>> #’#f) to retrieve that. But I’m suspicious that that is too simplistic. 
> 
> That `b` position, represents the negative blame position, which should be 
> the current contract region, which is often the current module. However, the 
> forms from `racket/contract/region` (including define/contract) can change 
> this using current-contract-region.
> 
> If you want to have that `b` be inferred as the current contract region for 
> you, you can use
> 
> (with-contract a #:result (-> string? integer?) (λ (x) x))
> 
> instead of (contract (-> string? integer?) (λ (x) x) 'a 
> (current-contract-region)).

Thanks, Alex! 

Kevin

-- 
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/CF0C0FDF-6418-4926-8B01-5ED04B65AD5D%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] [racet-userx] Syntax Class Question

2019-07-08 Thread Kevin Forchione
Hi guys, 
I’ve noticed that the library provides *some* syntax classes: id, str, char, 
expo… for various datatypes, but not all. Obviously being such a handy aspect 
of syntax-parse there’s probably a reason for this. Having spent a few days 
trying to roll my own for procedure I have to suspect this isn’t a simple 
thing. 

What’s the rationale in not reprinting them? 

Kevin

-- 
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/A1BC76B6-B8FA-4A4C-8A66-A2D467EE511A%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] raise-argument-error missing list?

2019-07-08 Thread Kevin Forchione


> On Jul 8, 2019, at 8:17 AM, David Storrs  wrote:
> 
> Note that in many cases it can be better to use a contract as opposed to an 
> explicit check.  For example, you could replace this:
> 
> (define (feed-animals cow sheep goose cat)
> (if (not (eq? goose 'goose))
>   (raise-argument-error 'feed-animals "'goose" 2 cow sheep goose cat)
>   "fed the animals"))
> 
> With this, which is precisely equivalent:
> 
> (define/contract (feed-animals cow sheep goose cat)
>(-> any/c any/c 'goose any/c any)
> "fed the animals")
> 
> 
> Or maybe you want to verify that neither cow, sheep, nor cat are also goose:
> 
> (define/contract (feed-animals cow sheep goose cat)
>(-> (not/c 'goose) (not/c 'goose) 'goose (not/c 'goose) any)
> "fed the animals")
> 
> Or, maybe you can accept either a symbol or a string for goose:
> 
> (define/contract (feed-animals cow sheep goose cat)
>(-> any/c any/c (or/c 'goose "goose") any/c any)
> "fed the animals")
> 
> Or maybe do that case-insensitively (I'm getting rid of the excess arguments 
> for brevity):
> 
> (define/contract (feed-animals goose)
>(-> (compose1 (curry string-ci=? "goose") ~a) any)
> "fed the animals")
> 
> Same as above, but let's insist that the return value be a non-empty string:
> 
> (define/contract (feed-animals goose)
>(-> (compose1 (curry string-ci=? "goose") ~a) non-empty-string?)
> "fed the animals")
> 
> If you really want to get nuts then you can do all kinds of inter-argument 
> checking in a contract.  Here's an actual contract that I use in my database 
> layer, for the 'upsert-rows' function:
> 
> (define symbol-string? (or/c symbol? string?))
> (define false-or-unsupplied? (or/c false? unsupplied-arg?))
> 
> (define/contract (upsert-rows #:table table-name
>   #:rows  rows
>   #:conflict-clause   conflict-clause
>   #:db[conn #f]
>   #:fields-to-update  [fields-to-update #f]
>   )
>   (->i (#:table   [table symbol-string?]
> #:rows[rows (or/c  (hash/c symbol-string? any/c)
>(listof (hash/c symbol-string? 
> any/c)))]
> #:conflict-clause [conflict-clause (or/c #f 'FAIL symbol-string?)] ; 
> 'FAIL is redundant with `symbol-string?`. It's there for clarity.
> )
>(
> #:db [db connection?]
> #:fields-to-update   [fields-to-update (or/c #f (non-empty-listof 
> symbol-string?))]
> )
>; If conflict clause is 'FAIL then fields-to-update must be #f or 
> unsupplied   
>; If conflict clause is #f then fields-to-update must be #f or 
> unsupplied  
>; If conflict clause is NOT #f then fields-to-update must be a list
> 
>#:pre (conflict-clause fields-to-update)
>(or  (and (equal? 'FAIL conflict-clause)
>  (false-or-unsupplied? fields-to-update))
> (and (false? conflict-clause) (false-or-unsupplied? 
> fields-to-update))
> (and conflict-clause (list? fields-to-update)))
>any)
> ...code…)

Thanks, David! I’ll have to look into using contracts in my code. Are there any 
downsides to contracts over the raising an error? 

Kevin

-- 
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/F9660627-85E0-4970-A357-E6C60486FCB9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] raise-argument-error missing list?

2019-07-08 Thread Kevin Forchione


> On Jul 8, 2019, at 10:41 AM, David Storrs  wrote:
> 
> Nothing specific that I'm aware of, but others could answer this better.  If 
> there are then they're probably related to speed.
> 
> Personally, I'm quite fond of them because they eliminate the need for a lot 
> of tests and make the code much more self-documenting.
> 
> Function contracts are detailed here: 
> https://docs.racket-lang.org/reference/function-contracts.html 
>   In the 
> left-hand navbar you'll see a bunch of related topics, like data-structure 
> contracts.

That would be my suspicion. I suppose it’s an art form balancing the checking 
with the speed checks. For instance, I’ve used contracts in the provide 
statement, and as I’ve noted in various places in the documentation (and my own 
experience) they only guard the boundaries of whatever they’d are associated 
with. But in a call chain we can end up verifying a value repeatedly and 
wouldn’t it be marvelous if we could somehow pass it’s certification in syntax 
(no, I don’t know what I’m talking about, just dreaming) so that verification 
would only happen once and when needed? 

Kevin

-- 
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/D3D604D5-458B-4CA2-9161-47BFD9D0F54A%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] [racet-userx] Syntax Class Question

2019-07-08 Thread Kevin Forchione


> On Jul 8, 2019, at 10:50 AM, David Storrs  wrote:
> 
> 
> 
> On Mon, Jul 8, 2019 at 12:59 PM Kevin Forchione  <mailto:lyss...@gmail.com>> wrote:
> Hi guys, 
> I’ve noticed that the library provides *some* syntax classes: id, str, char, 
> expo… for various datatypes, but not all. Obviously being such a handy aspect 
> of syntax-parse there’s probably a reason for this. Having spent a few days 
> trying to roll my own for procedure I have to suspect this isn’t a simple 
> thing. 
> 
> What’s the rationale in not reprinting them? 
> 
> Mat.* and/or others will be able to answer this more definitively, but I 
> suspect the issue is that syntax-parse works at phase 1, a macro-expansion 
> (similar to "compile time") phase, as opposed to runtime.  As a result, the 
> thing that will be in that slot is an sexp like (lambda (x) x) instead of a 
> #.  It's easy to tell that the sexp is not an identifier, string, 
> etc, but determining if it will produce a # requires actually 
> evaluating it -- what if it was (and foo bar) or (* x 9) instead of (lambda 
> (x) x)?

Yes, that’s been one of my thoughts well. For example, if it’s an identifier I 
can use syntax-case and a guard to check for identifier-binding, but the lambda 
case seems to mean interrogating the syntax for lambda, or relying on some 
syntactical structure pattern and then dealing with it later in a function. 

It’s a matter of control. I’m constantly being amazed at how rich the 
mechanisms are for manipulating syntax. And never surprised when there’s a 
better way to do it. The Racket development team have created something truly 
remarkable. 

Kevin

-- 
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/B6DE0408-2A01-42B6-A068-D49FB68B2CB8%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] [racket users] make-keyword-procedure follow-up

2019-08-30 Thread Kevin Forchione


> On Aug 30, 2019, at 1:19 AM, Philip McGrath  wrote:
> 
> Hi Kevin,
> 
> This is interesting! A number of people have wanted conveniences around 
> `keyword-apply` and accepting the same keywords as some other function. (The 
> trouble is, different people have different ideas of what those conveniences 
> should be.)
> 
> To start with, I had a few small suggestions about the code you sent: 
> `keyword-apply/filter` doesn't need to be a macro, and your macro should use 
> `fn` rather than `h`;
> the second result of `procedure-keywords` can be `#f` if the given procedure 
> accepts all keywords;
> `for/lists` might be more convenient than `for/fold`;
> I think some of the cases in `filter/kw` get the filtering backwards;
> keywords can be `quote`-ed as values, so you don't need so many 
> symbol-to-string-to-keyword conversions;
> using `set!` this way will cause lots of problems;
> there's no need for `list->vector` in `get-kw-val`; and
> in `def`, it might be better to use syntax parameters than to break hygiene.
> You may know this, but all keyword-accepting functions in Racket are 
> effectively implemented with `make-keyword-procedure`: the variants of 
> `lambda` and `define` that use `kw-formals` are macros that expand to more 
> primitive versions that don't know about keywords. The macros also do some 
> optimization where possible. For inspiration, you might be interested in the 
> implementation in 
> https://github.com/racket/racket/blob/master/racket/collects/racket/private/kw.rkt
>  
> 
> 
> For fun, I wrote a version that illustrates some of these suggestions and and 
> tries to do more work at compile-time. Be warned that it is not thoroughly 
> tested! I'm pasting it below, and I've also put it up as a Gist at 
> https://gist.github.com/LiberalArtist/292b6e99421bc76315110a59c0ce2b0d 
> 
> 
> -Philip
Thanks, Philip! Sorry for the bug in the keyword-apply/filter macro. I 
discovered it as well last night when I decided to convert the macro to a 
function. Glad others are working on this idea as well, perhaps something will 
find its way into the main package. As with much of my own code development  
No, I hadn’t realized make-keyword-procedure formed the basis of Racet keyword 
functions — I’m often being surprised like this — seems somewhere along the way 
I missed some fundamental primer of elementary concepts :) 

I’ve not had a chance to peruse the code and websites yet, but as clarification 
of what I have in mind: The problem I’m working on involves a function call f, 
in which some of the parameters are used to lookup functions in a table and 
then apply the remaining parameters in the application of that retrieved 
function g. All was going smoothly until I stored a function in the table that 
used keywords. So the filtering I’ve been working on would allow f to reference 
its own keywords without complaining about g’s and to “filter out” f’s keywords 
from those passed to g when they did not overlap (so to speak). Any additional 
keywords passed in the function call that were not defined by g would then be 
eared by g, which is why Ive been referring to f as a “pass-through”.  So if f 
defined #:foo and #:bar and g defined #:foo and #:baz f would bind any #:foo 
and #:bar values (or use its default values) for its own process, but pass g 
#:foo and #:baz as provided by the parameters passed in the call too f. Of 
course that lasts the flexibility that the #:foo value passed to f might be 
different from that of g — but that’s where I decided to draw the line :) 

Kevin

-- 
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/D3F9EF44-D45D-4D02-A571-257F074CA499%40gmail.com.


[racket-users] racket users] make-keyword-procedure follow-up

2019-08-29 Thread Kevin Forchione



> On Aug 29, 2019, at 1:24 PM, Kevin Forchione  wrote:
> 
> Hi guys,
> I’ve been working for a little while with the idea of being able to pass 
> keyword arguments through a function that doesn’t define them. Additionally I 
> wanted to allow the “pass-through” function to define its own keywords. 
> Additionally didn’t want to have to pre-specify what function might be on the 
> receiving end of the call. But finally, if both pass-through and called 
> functions define the same keywords I didn’t want to have to differentiate 
> between them. 
> 
> - This seems to involve some combination of make-keyword-procedure and 
> keyword-apply.
> -  Since make-keyword-procedure expects a “vanilla” function (one without 
> keywords specified) I decided to define a macro that would wrap the function 
> in a let  that with default bindings for each keyword defined by the 
> pass-through. Inside the function I would then assign any values provided by 
> the function call to those variables. 
> - Additionally I would build a parameterized list of keywords defined by the 
> pass-through chain. These would be used in conjunction with the keyword list 
> produced by procedure-keywords and the keywords/values captured by the 
> function call to “filter” the lists used by keyword-apply. The idea being to 
> eliminate any keyword/values supplied to the pass-through and defined by the 
> pass-through that were not defined by the  called function. This would allow 
> keywords not defined by either to be error by the called function. 
> 
> As you can see, it’s a convoluted approach and I’m not sure how robust it 
> actually. I’m presenting working code (for my test cases…) but also wondering 
> if someone hasn’t already crated that wheel. :) 
A little syntactic sugar makes it appear more palatable with the addition of:

(define-syntax (keyword-apply/filter stx)
  (syntax-parse stx
[(_ fn kw kv args)
 #'(let ()
 (define-values (rkw akw) (procedure-keywords h))
 (define-values (Δkw Δkv) (filter/kw (current-caller-kw) akw kw kv))
 (keyword-apply fn
  Δkw
  Δkv
  args))]))

And now the definitions are somewhat clearer:

(define (h #:c c . x)
  (list c x))
(def (g ((c 0)) . args)
  (list c (keyword-apply/filter h kw kv args)))
(def (f ((a 0)(b 0)) n p . ns)
  (list kw kv a b n p ns (keyword-apply/filter g kw kv ns)))

Kevin

-- 
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/751B8754-6244-4A44-B779-ECD52DA070B5%40gmail.com.


[racket-users] [racket users] make-keyword-procedure follow-up

2019-08-29 Thread Kevin Forchione
Hi guys,
I’ve been working for a little while with the idea of being able to pass 
keyword arguments through a function that doesn’t define them. Additionally I 
wanted to allow the “pass-through” function to define its own keywords. 
Additionally didn’t want to have to pre-specify what function might be on the 
receiving end of the call. But finally, if both pass-through and called 
functions define the same keywords I didn’t want to have to differentiate 
between them. 

- This seems to involve some combination of make-keyword-procedure and 
keyword-apply.
-  Since make-keyword-procedure expects a “vanilla” function (one without 
keywords specified) I decided to define a macro that would wrap the function in 
a let  that with default bindings for each keyword defined by the pass-through. 
Inside the function I would then assign any values provided by the function 
call to those variables. 
- Additionally I would build a parameterized list of keywords defined by the 
pass-through chain. These would be used in conjunction with the keyword list 
produced by procedure-keywords and the keywords/values captured by the function 
call to “filter” the lists used by keyword-apply. The idea being to eliminate 
any keyword/values supplied to the pass-through and defined by the pass-through 
that were not defined by the  called function. This would allow keywords not 
defined by either to be error by the called function. 

As you can see, it’s a convoluted approach and I’m not sure how robust it 
actually. I’m presenting working code (for my test cases…) but also wondering 
if someone hasn’t already crated that wheel. :) 

#lang racket

(require (for-syntax syntax/parse
 racket/syntax))

(define current-caller-kw (make-parameter '()))

(define (get-kw-val w v kw kv)
  (define key (string->keyword (symbol->string w)))
  (define kws (list->vector kw))
  (define idx (vector-member key kws))
  (cond
[(false? idx) v]
[else (define kvs (list->vector kv))
  (vector-ref kvs idx)]))

(define-syntax (def stx)
  (syntax-parse stx
[(_ (f ((w v) ...) k ... . ks) body0 body ...)
 (with-syntax ([kw (format-id #'f "kw")]
   [kv (format-id #'f "kv")])
   #'(define f
   (let ([w v] ...)
 (make-keyword-procedure
  (λ (kw kv k ... . ks)
(parameterize ([current-caller-kw
(append (current-caller-kw)
(map (λ (x) (string->keyword 
(symbol->string x)))
 (list 'w ...)))])
  (set! w (get-kw-val 'w w kw kv)) ...
body0 body ...))]))

(define (filter/kw ckw fkw kw kv)
  (cond
[(empty? ckw) (values kw kv)]
[(empty? (remove* fkw ckw)) (values kw kv)]
[else
 (define diff (remove* fkw ckw))
 (define vkw (list->vector kw))
 (define vkv (list->vector kv))
 (for/fold ([wacc '()] [vacc '()])
   ([v kv]
[k kw] #:unless (member k diff))
   (values (append wacc (list k)) (append vacc (list v]))

(define (h #:c c . x) (list c x))

(def (g ((c 0)) . args)
  (define-values (rkw akw) (procedure-keywords h))
  (define-values (Δkw Δkv) (filter/kw (current-caller-kw) akw kw kv))
  (list c (keyword-apply h
 Δkw
 Δkv
 args)))
(def (f ((a 0)(b 0)) n p . ns) (list kw kv a b n p ns (keyword-apply g
 kw
 kv
 ns)))


;=> '((#:a #:c) (42 52) 42 0 2 3 (4 5) (52 (52 (4 5
(f 2 3 4 5 #:a 42 #:c 52)
;=> application: procedure does not expect an argument with given keyword
;  procedure: h
;  given keyword: #:z
;  arguments...:
(f 2 3 4 5 #:z 42 #:c 52)

Kevin

-- 
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/27D5D96D-F9D9-4ECB-9AE0-92FD1EB065C8%40gmail.com.


[racket-users] [racket users] Contracts and make-keyword-procedure question

2019-08-23 Thread Kevin Forchione
Suppose I have the following:

(define/contract foo (-> ??? any/c symbol? symbol? any/c any)
   (make-keyword-procedure (lambda (kw kv a b . args) do-something …)))

What sort of contract would I give to the kw parameter so that it basically 
accepts a list of unspecified keywords? What I’m doing is passing that 
information along to keyword-apply and the function derived from other argument 
data. I’d like to be able to skip the contract on the keywords at the moment, 
and simply enforce the other arguments. 

What I get is an error message that would say that foo expects no keywords, but 
was supplied them, as might be the case, even with any/c specified. 

Any suggestions are appreciated.

Kevin

-- 
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/6AA60DD2-7A42-4527-AED7-4A51FF0146B8%40gmail.com.


[racket-users] [racket ursers] Keyword question

2019-08-22 Thread Kevin Forchione



> On Aug 22, 2019, at 1:33 PM, Kevin Forchione  wrote:
> 
> Hi guys,
> Suppose I have something like the following:
> 
> (define (f  g . args) 
>   (apply g args))
> 
> How would I be able to pass keyword arguments to g? 

After racking my brains for the common lisp  and googling for 
the scheme/Racket equivalent, stumbling through  mzlib/kw and finally a bit of 
digging through racket procedure documentation I cobbled together an approach 
that seems to do what I’m after. So I thought I’d share. Here’s an example:

#lang racket


(define (foo #:a (a 0) #:b (b 1) c (d 3) . rst) (list a b c d rst))

(define show
  (make-keyword-procedure (λ (kws kw-args f . args) (keyword-apply f kws 
kw-args args

(show foo #:a 10 2 3 4 5 6 7)
=> '(10 1 2 3 (4 5 6 7))

Now apparently any keywords defined for show itself are captured in the kWh and 
kw-args lists and would need to be filtered out of those lists before tasing 
them on to f, but that shouldn’t be too difficult.

Kevin

-- 
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/395CF1DB-3B85-4FFA-9C1B-5566EB2CC60F%40gmail.com.


[racket-users] [racket ursers] Keyword question

2019-08-22 Thread Kevin Forchione
Hi guys,
Suppose I have something like the following:

(define (f  g . args) 
   (apply g args))

How would I be able to pass keyword arguments to g? 

Kevin

-- 
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/CAD069C0-09B7-4984-B1F6-19AE2A85CF29%40gmail.com.


Re: [racket-users] [racket users] module question

2019-08-07 Thread Kevin Forchione


> On Aug 6, 2019, at 4:06 PM, Sorawee Porncharoenwase  
> wrote:
> 
> (module B racket
>   (require (submod ".." A))
>   (printf "X=~a~%" X))

Why doesn’t printf display anything ? 

Kevin 

-- 
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/D0788D42-32EE-4898-B1BB-8795628B06C8%40gmail.com.


Re: [racket-users] [racket users] module question

2019-08-07 Thread Kevin Forchione


> On Aug 7, 2019, at 8:55 AM, Kevin Forchione  wrote:
> 
> 
> 
>> On Aug 6, 2019, at 4:06 PM, Sorawee Porncharoenwase > <mailto:sorawee.pw...@gmail.com>> wrote:
>> 
>> (module B racket
>>   (require (submod ".." A))
>>   (printf "X=~a~%" X))
> 
> Why doesn’t printf display anything ? 

Oh, wait. modules are “lazy” until they’re required. Something like that. I 
think I’m beginning to understand. :) 

#lang racket


(module A racket
  (provide X)
  (define X 5)
  (printf "A.X=~a~%" X))

(module B racket
  (require (submod ".." A))
  (printf "B.X=~a~%" X))


(require ‘B)

Kevin

-- 
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/D38B2472-D673-49BB-AF89-1B9FF9A3EFC1%40gmail.com.


[racket-users] [racket users] make-posn question

2019-08-06 Thread Kevin Forchione
Hi guys, 
I love working with the 2htdp/universe and 2htdp/image packages. But polygon 
requires posts (and some of the other functions do too). 2htdp/image doesn’t 
include a definition. What’s the best library to require for these? I tried 
making my own struct and was surprised that the function didn’t like it. 
Apparently it wants a specific post? 

Kevin 

-- 
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/D69DC921-5529-49DF-9F60-ACA4FC317191%40gmail.com.


[racket-users] [racket users] module question

2019-08-06 Thread Kevin Forchione
Is there a way to define 2 modules within a file and reference them or is a 
file limited to 1 module only (but may have multiple submodules)?

Here’s a small sample: 

#lang racket

(module A racket
˘  (provide X)
  (define X 'foo))

(module B racket
  (require 'A)
  (printf "X=~a~%" X))

Apparently, as I understand it, I’m already nesting modules within the #lang 
racket. But I’m not sure how to require A from within B in this situation. 

Kevin

-- 
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/6326DC5D-44D5-4CE9-B2B8-E781A6D51561%40gmail.com.


Re: [racket-users] datatypes

2019-07-17 Thread Kevin Forchione


> On Jul 16, 2019, at 10:36 PM, Alex Knauth  wrote:
> 
> 
> 
>> On Jul 17, 2019, at 12:16 AM, Kevin Forchione > <mailto:lyss...@gmail.com>> wrote:
>> 
>> Hi guys,
>> Is there any function in Racket that will return a symbol representation of 
>> a value’s datatype? We can interrogate them with predicates, but it occurs 
>> to me that this information must be carried in the object’s syntax 
>> somewhere… otherwise the syntax->datum wouldn’t work. Of course I may be 
>> overlooking something :) 
> 
> I'm not sure what you mean by "carried in the object's syntax" or why 
> syntax->datum is relevant. Could you clarify with a concrete example?
> 
> Anyway putting aside the syntax part and only looking at values, the 
> `describe` [1] package, in particular the `variant` [2] function might be 
> helpful to you or not depending on what you mean by "datatype”.

Thanks, Alex! That’s exactly what I’m looking for. My remark on syntax->datum. 
was simply speculation. A better way to put it is: how does variant able to 
convert a racket value into a symbol representing its datatype? I was thinking 
that information must be part of the object’s syntax-object, but it doesn’t 
look like it. Still, variant reports ‘(a . b) as a ‘pair. and that’s amazing. 
How is it obtaining that information?

Kevin

-- 
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/87B4031D-DD8A-439F-B954-B94C03002C5F%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Contracts referring to earlier elements?

2019-07-18 Thread Kevin Forchione
Hi guys,
This is a little tricky to explain, so I’ll give a small example:

[define/contract [foo x) (-> integer? not-x/c) body …)

In this case the not-x/c is what I’m asking about. Some way that the contract 
can refer to a previous argument value? Ordinarily this would be a predicate, 
but the parameters don’t appear to be in the scope of the contract. so ((λ (v) 
(not (= v x))) won’t work here, but it gets at the issue I”m interested in. I 
could of course interrogate the arguments inside the body of the function, but 
was wondering if a contract could do so. 

Kevin

-- 
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/33F99A77-8609-4C37-AF59-E407A38A066A%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] datatypes

2019-07-16 Thread Kevin Forchione
Hi guys,
Is there any function in Racket that will return a symbol representation of a 
value’s datatype? We can interrogate them with predicates, but it occurs to me 
that this information must be carried in the object’s syntax somewhere… 
otherwise the syntax->datum wouldn’t work. Of course I may be overlooking 
something :) 

Kevin

-- 
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/F70A7132-EBCC-48C9-84CB-43571402F543%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] [racket users] Generics question

2020-03-03 Thread Kevin Forchione



> On Mar 3, 2020, at 10:48 AM, Jon Zeppieri  wrote:
> 
> On Tue, Mar 3, 2020 at 12:37 PM Kevin Forchione  wrote:
>> 
>> Thanks!  That brings me a little closer in appreciating the comments I’ve 
>> read about replacing object-oriented code with structs and methods.
>> 
>> Is this part of the racket/generic or the Multimethods library? The example 
>> you provide works from racket/generic, but the search in docs pulls up only 
>> the multimethod docs and the examples don’t work from racket/generic.
>> 
>> Kevin
> 
> It's in racket/generic. Here's a link to the documentation for
> `define/generic`:
> https://docs.racket-lang.org/reference/struct-generics.html?q=define%2Fgeneric#%28form._%28%28lib._racket%2Fgeneric..rkt%29._define%2Fgeneric%29%29
> 
> - Jon

Oh, I see. I searched for “define-generic” instead of “define/generic”! Well, 
that explains my confusion and opens up more options as well. :) 

Kevin

-- 
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/5FFB3F9E-0C68-4F6A-B36A-41D496F22103%40gmail.com.


Re: [racket-users] [racket users] Generics question

2020-03-03 Thread Kevin Forchione


> On Mar 3, 2020, at 9:19 AM, Jon Zeppieri  wrote:
> 
> (struct A (this other) #:transparent
>  #:methods gen:foo
>  [(define/generic generic-foo do-foo)
>   (define (do-foo foo)
> (printf "other=~a ~a"
> (A-this foo)
> (generic-foo (A-other foo])


Thanks!  That brings me a little closer in appreciating the comments I’ve read 
about replacing object-oriented code with structs and methods. 

Is this part of the racket/generic or the Multimethods library? The example you 
provide works from racket/generic, but the search in docs pulls up only the 
multimethod docs and the examples don’t work from racket/generic. 

Kevin

-- 
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/43B656D0-0811-4E15-95FE-8945655AC68A%40gmail.com.


[racket-users] [racket users] Generics question

2020-03-03 Thread Kevin Forchione
Hi guys,
If I create a generic, say foo, for a particular struct and then later 
reference that method on a different type of struct from within the handler 
method I get an error because the call goes to the original structs method and 
not to the method of the other struct. Is there a way to do this?

Here’s a very artificial example:

#lang racket

(require racket/generic)

(define-generics foo
[do-foo foo])

(struct A (this other) #:transparent
  #:methods gen:foo
  [(define (do-foo foo)
 (printf "other=~a ~a"
 (A-this foo)
 (do-foo (A-other foo])
(struct B (lst) #:transparent
  #:methods gen:foo
  [(define (do-foo foo)
 (printf "lst=~a"
 (B-lst foo)))])

(define b (B '(x y z)))
(define a (A 'a b))

(do-foo b) ;=> lst=(x y z)

(do-foo a) ;=> A-this: contract violation
  expected: A?
  given: (B '(x y z))

Thanks, 
Kevin

-- 
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/86CD099C-EC82-4F97-B20A-784933E3C6FC%40gmail.com.


[racket-users] [racket users] Macro literal "|"

2020-02-03 Thread Kevin Forchione
Hi guys,
I’ve been  trying to figure out how to use “|” in a macro. I’ve got syntax like 
this in mind:

(foo A | B) 

Not sure if I can do this because the reader expects a pair. If “|” isn’t a 
convenient literal to work with is there an alternative others have used that 
represents more or less the idea of “or” or “alternate”?

Thanks!

Kevin

-- 
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/447100AA-DB45-46C3-A7DC-2705A1668302%40gmail.com.


[racket-users] [racket users] struct #:methods question

2020-04-20 Thread Kevin Forchione
Hi guys,
How do you return an instance of the structure type from the struct’s 
#:methods? This is would seem to be a common situation, but it has me stumped.

Kevin

-- 
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/EE404363-995C-4888-8B43-E463EB3C7418%40gmail.com.


[racket-users] [racket users] describe variant issue?

2020-09-15 Thread Kevin Forchione
Hi guys,
I’m not sure why the describe library’s variant is always returning ‘simple 
regardless of numeric value. For instance, the docmentation says:

(variant 

 1) -> fixnum-integer

But when I run it under Dr Racket 7.8 [cs] it returns ‘simple for this, as well 
as for 10.3  as well as pi, 2/3, and 0+1i.

Any ideas why this is happening?

Thanks!

Kevin

-- 
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/367E5C0C-FA1C-4546-A586-54135D264C6B%40gmail.com.


Re: [racket-users] [racket users] make-keyword-procedure follow-up

2020-10-09 Thread Kevin Forchione

> On Aug 30, 2019, at 1:19 AM, Philip McGrath  wrote:
> 
> Hi Kevin,
> 
> This is interesting! A number of people have wanted conveniences around 
> `keyword-apply` and accepting the same keywords as some other function. (The 
> trouble is, different people have different ideas of what those conveniences 
> should be.)
> 
> To start with, I had a few small suggestions about the code you sent: 
> `keyword-apply/filter` doesn't need to be a macro, and your macro should use 
> `fn` rather than `h`;
> the second result of `procedure-keywords` can be `#f` if the given procedure 
> accepts all keywords;
> `for/lists` might be more convenient than `for/fold`;
> I think some of the cases in `filter/kw` get the filtering backwards;
> keywords can be `quote`-ed as values, so you don't need so many 
> symbol-to-string-to-keyword conversions;
> using `set!` this way will cause lots of problems;
> there's no need for `list->vector` in `get-kw-val`; and
> in `def`, it might be better to use syntax parameters than to break hygiene.
> You may know this, but all keyword-accepting functions in Racket are 
> effectively implemented with `make-keyword-procedure`: the variants of 
> `lambda` and `define` that use `kw-formals` are macros that expand to more 
> primitive versions that don't know about keywords. The macros also do some 
> optimization where possible. For inspiration, you might be interested in the 
> implementation in 
> https://github.com/racket/racket/blob/master/racket/collects/racket/private/kw.rkt
>  
> 
> 
> For fun, I wrote a version that illustrates some of these suggestions and and 
> tries to do more work at compile-time. Be warned that it is not thoroughly 
> tested! I'm pasting it below, and I've also put it up as a Gist at 
> https://gist.github.com/LiberalArtist/292b6e99421bc76315110a59c0ce2b0d 
> 
> 
> -Philip

Hi Philip,
I’ve been using your kw-pass-through-lambda.rkt module quite happily for a 
while now. One issue I’ve run into though is that the local-keyword-apply 
appears to have an issue when the return is multiple values. For instance, in 
the test module, if you replace the:

  (define (h #:c c . x)
(list c x))


With:

  (define (h #:c c . x)
(values c x))

You’ll get an error: “Returned two values to single value return context”

Is there a way to fix this?

Kevin


-- 
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/2A70A1D7-741E-4CDF-A29E-49BF1BF14EB7%40gmail.com.


[racket-users] [racket users] scribble using @ as text?

2020-09-24 Thread Kevin Forchione
Hi guys,
I’ve been racking my brains and going through scribble manuals trying to figure 
out how to do something as simple as proceed a sentence like: The @ is used in 
a scribble command. I’m sure I’m overlooking something very basic, since the @ 
is referenced all over scribble documentation. 

Any help is appreciated!

Kevin

-- 
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/8187F519-D648-472C-8B99-45B28DFD4BC0%40gmail.com.


[racket-users] [racket users] Naming conventions

2020-09-18 Thread Kevin Forchione
Hi guys,
Racket has some naming conventions that I’ve come across: parameters prefixed 
with “current-“, class and interfaces suffixed with % and <%> respectively. 
I’ve not stumbled across one for structs yet. 

Suppose I have a circle struct and want to distinguish this from the  
http/image circle function? Or suppose I have symbols that are never bound to 
anything? 

Kevin

-- 
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/9B9B9785-3B2A-4DBB-BC2E-E3D543CB4D21%40gmail.com.


Re: [racket-users] [racket users] describe variant issue?

2020-09-17 Thread Kevin Forchione



> On Sep 15, 2020, at 3:11 PM, Sam Tobin-Hochstadt  wrote:
> 
> This is a difference in behavior between Racket BC and Racket CS, and
> not something in the describe library:
> 
> [samth@homer:~/work/teaching/c211 (master) racket-7.8] racket
> Welcome to Racket v7.8.
>> (struct->vector 5)
> '#(struct:fixnum-integer ...)
>> ^D
> [samth@homer:~/work/teaching/c211 (master) plt] racket
> Welcome to Racket v7.8.0.9 [cs].
>> (struct->vector 5)
> '#(struct:simple …)


Is this going to be the go-forward stance for Racket? Or is this still a work 
in progress? Will it be left up to the code to determine types through 
predicate checking?

Thanks!

Kevin

-- 
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/F42194F9-ADA3-4158-BCBA-3A65F2108AB4%40gmail.com.


Re: [racket-users] [racket users] Macros sharing data?

2020-10-21 Thread Kevin Forchione



> On Oct 21, 2020, at 10:33 AM, William G Hatch  wrote:
> 
> On Wed, Oct 21, 2020 at 10:07:12AM -0700, Kevin Forchione wrote:
>>  Hi guys,
>> Suppose I have a macro that computes a value and then calls another macro in 
>> its template. Is there a way to share that data with the 2nd macro without 
>> passing it as an argument?
> 
> Take a look at syntax parameters and syntax-local-value.
> 
> Syntax parameters, somewhat similar to `parameterize` for runtime
> code, allow macros to have an implicit communication channel.  The
> macro that `syntax-parameterize`es sets a value for the given
> parameter which is usually accessed by simply using the syntax
> parameter in its template somewhere.  The syntax parameter may even be
> passed in to the macro as an argument and thus end up in the template.
> This is how `this` gets its value in the class macro -- it's a syntax
> parameter.
> 
> However, if you want an inner macro to be able to inspect the value
> given to a syntax parameter, it can use `syntax-parameter-value` to
> get the current value out and do something with it.
> 
> `syntax-local-value` is another useful tool for macros to communicate.
> When you `define-syntax` an identifier, you give it a transformer
> binding.  Usually the value is a procedure (a macro transformer), but
> it can actually be other data.  One popular type of data to use is a
> struct that implements `prop:procedure`, and can thus act as a macro
> transformer as well as a storage place for data (which can be
> inspected by the struct's procedure interface or by other code).  To
> access this data, you pass the identifier (as a syntax object) that
> you `define-syntax`ed to `syntax-local-value`.
> 
> Without knowing more about what you're trying to do I'm not sure what
> more concrete advice I can give, but syntax parameters and
> `syntax-local-value` are two of the killer features that make Racket's
> macro system so powerful, so I recommend anyone who wants to use
> macros to become familiar with them.


Here’s a toy example. It generates an error, but hopefully conveys the idea I’m 
trying to express. 

#lang racket

(require (for-syntax syntax/parse)
 racket/stxparam
 racket/stxparam-exptime)

(define-syntax-parameter mval 1)

(define-syntax (foo stx)
  (syntax-parse stx
[(_ m:number n:number)
 #'(syntax-parameterize ([mval m])
 (bar n))]))

(define-syntax (bar stx)
  (syntax-parse stx
[(_ n) #'(* (syntax-parameter-value mval) n)]))

(foo 3 5)

Kevin

-- 
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/0B80489F-8F0A-4171-AAD6-646B11C585F3%40gmail.com.


Re: [racket-users] [racket users] Macros sharing data?

2020-10-21 Thread Kevin Forchione


> 
> Here’s a toy example. It generates an error, but hopefully conveys the idea 
> I’m trying to express. 
> 
> #lang racket
> 
> (require (for-syntax syntax/parse)
> racket/stxparam
> racket/stxparam-exptime)
> 
> (define-syntax-parameter mval 1)
> 
> (define-syntax (foo stx)
>  (syntax-parse stx
>[(_ m:number n:number)
> #'(syntax-parameterize ([mval m])
> (bar n))]))
> 
> (define-syntax (bar stx)
>  (syntax-parse stx
>[(_ n) #'(* (syntax-parameter-value mval) n)]))
> 
> (foo 3 5)

It dawned on me that since both computations take place at runtime I can simply 
use a parameter!

Kevin

-- 
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/AC61E773-7468-4A1E-916A-F8939EDA5EDC%40gmail.com.


[racket-users] [racket users] %app question

2020-08-13 Thread Kevin Forchione
Hi guys,

Pollen makes use of something like this:

(require syntax/parse/define)

(define-simple-macro (#%top . x) 'x)


and it comes in handy in some of my projects. But I’m wondering if there’s an 
equivalent for redirecting an application that hasn’t been defined? 

In other words, if foo is not a procedure then (foo 1 2 3) would redirect to 
(do-this foo 1 2 3) where do-this is defined?

Any help is appreciated. 

Thanks!

Kevin

-- 
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/B7AAB6F2-9BBB-4C81-B29F-4B29B6F687D1%40gmail.com.


Re: [racket-users] [racket users] %app question

2020-08-14 Thread Kevin Forchione


> On Aug 13, 2020, at 1:05 PM, Jens Axel Søgaard  wrote:
> 
> Den tor. 13. aug. 2020 kl. 21.55 skrev Kevin Forchione  <mailto:lyss...@gmail.com>>:
> Hi guys,
> 
> In Bracket [1] used your idea to produce s-expression, if the first argument
> of #%app isn't a function:
> 
> ; In the BRACKET language an application of
>   ; a non-function evaluates to an expression.
>   (define-syntax (sym-app stx)
> (syntax-case stx ()
>   [(_ op arg ...)
>(quasisyntax/loc stx
>  (let ([o op])
>(if (procedure? o)
>#,(syntax/loc stx (#%app o arg ...))
>(if (holdable? o)
>(cons o '(arg ...))
>(cons o (list arg ...))]))
> 
> There is an additional wrinkle - if a function is "holdable" it "holds" 
> (postpones) the 
> evaluation of its arguments. This can simply we be removed, if you don't need 
> it.
> 
> More details here:
> 
> https://github.com/soegaard/bracket/blob/master/bracket/bracket.rkt#L80 
> <https://github.com/soegaard/bracket/blob/master/bracket/bracket.rkt#L80>
Thanks! With a little modification that does the trick! 

Kevin

-- 
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/1358F277-7B1F-4C25-B791-96F70807F641%40gmail.com.


[racket-users] [racket users] Detecting characters in symbols in macros

2020-12-09 Thread Kevin Forchione
Hi guys,
Is there a way to detect a character in a symbol in a macro so that one branch 
of the syntax-parse would be chosen or discarded based on that?

Here’s roughly what I’m getting at….

#lang racket

(require (for-syntax syntax/parse))

(define-syntax (foo stx)
  (syntax-parse stx
[(_ arg) #'(do-$ arg)]
[(_ arg) #'(do-other arg)]))

(foo $abc)
(foo abc)

I was thinking expo/c might come into play here, but maybe there’s another 
approach?

Thanks!

Kevin

-- 
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/FE7ED3FD-EAF0-4F03-8D3C-94D2092A9721%40gmail.com.


Re: [racket-users] [racket users] Pollen tag question

2020-10-30 Thread Kevin Forchione


> On Oct 29, 2020, at 9:21 PM, Sorawee Porncharoenwase 
>  wrote:
> 
> Whoops. I meant:
> 
> #lang pollen 
> 
> ◊(define (vb . s) s)
> 
> ◊vb{ A B
>C D}
> and the output is:
> 
> '(" A B" "\n" "   " "C D")
> 
> On Thu, Oct 29, 2020 at 9:19 PM Sorawee Porncharoenwase 
> mailto:sorawee.pw...@gmail.com>> wrote:
> I think the issue is with vb. How does it work?
> 
> If you try
> 
> #lang pollen
> 
> @(define (vb . s) s)
> 
> ◊vb{ A B
>C D}
> you will find that it outputs:
> 
> '(vb " A B"
>  "\n" 
>  "   " 
>  "C D")
> The third element is the space before “C”. It's not discarded.
> 
> Also notice that the "start" of the line is at the marker shown below
> 
> 
> 
> 
> #lang pollen
> 
> @(define (vb . s) s)
> 
> ◊vb{ A B
>  >>>   C D}
> This is due to how @ syntax 
> 
>  works.


Here’s my pollen.rkt:

#lang racket/base
(require pollen/decode pollen/misc/tutorial txexpr
 #;(only-in racket make-list string->number))
(provide (all-defined-out))
(define (root . elements)
   (txexpr 'root empty (decode-elements elements
 #:txexpr-elements-proc decode-paragraphs
 #:string-proc (compose1 smart-quotes smart-dashes

And  here’s an initial test.html.pm:


#lang pollen

   A   B
   C   D

Which produces
'(root "A   B" (br) "C   D")

Now if I add the vb as you’ve done, but don’t use the tag:

#lang pollen
◊(define (vb . s) s)

   A   B
   C   D

I get this:
'(root "A   B" (br) "   " "C   D")


Kevin


-- 
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/2202E524-AAC0-44D3-9B4B-C49216733900%40gmail.com.


Re: [racket-users] [racket users] Pollen tag question

2020-10-30 Thread Kevin Forchione
If I remove my pollen.rkt from the directory and use:

#lang pollen



   A   B
   C   D

I get:
'(root "A   B" "\n" "C   D”)

But if I use:
#lang pollen
◊(define foo "foo")


   A   B
   C   D

I get:
'(root "   " "A   B" "\n" "   " "C   D")

Ievin

-- 
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/54B1567F-7ED0-4236-8220-BA74D4334EBF%40gmail.com.


Re: [racket-users] [racket users] Pollen tag question

2020-10-30 Thread Kevin Forchione


> On Oct 30, 2020, at 12:25 PM, Matthew Butterick  wrote:
> 
> Spaces at the beginning of body lines do not appear in the resulting 
> S-expressions, but the column of each line is noticed, and all-space 
> indentation strings are added so the result has the same indentation … If the 
> first string came from the opening { line, it is not prepended with an 
> indentation”

Thanks, Matthew! Understanding dawns. So the padding of lines is relative to 
the “{“ and not from the beginning of the editor line as I was assuming. How 
very clever. That makes alignment much easier than I’d thought!  

Is this mentioned anywhere in the pollen tutorials? I must have missed it.

Kevin 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/2E23F40B-B3D9-495A-ACF6-34447B95A8A1%40gmail.com.


[racket-users] [racket users] Macros sharing data?

2020-10-21 Thread Kevin Forchione
Hi guys,
Suppose I have a macro that computes a value and then calls another macro in 
its template. Is there a way to share that data with the 2nd macro without 
passing it as an argument?

Thanks!
Kevin

-- 
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/5425EC92-110D-47B4-BCFB-D2B6C09BBF32%40gmail.com.


[racket-users] [racket users] Pollen tag question

2020-10-29 Thread Kevin Forchione
Hi guys,
I’ve noticed that the elements being sent to a pollen tag don’t preserve the 
spacing when the text spans multiple lines for any space occurring before 
characters on the subsequent line, although does preserve the spacing between 
characters on that line.Is thes intentional?

For example: Racket 7.8 [cs], latest pollen version: 

◊vb{ A B
 C D}

Regardless of how many spaces are before the C, the tag elements will only 
return a single space, although it preserves the spacing between C and D. 

Is that the expected result? It seems counter intuitive, as the spacing before 
A is preserved. 

Kevin

-- 
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/2ECCF698-BD5D-4421-B28A-EC74471715B6%40gmail.com.


[racket-users] [racket users] list question

2021-02-25 Thread Kevin Forchione
Hi guys,
I’m trying to find out what this process may be called. Suppose you have lists 
of various lengths:

‘(A B C D E F)
‘(1 2)
‘(3 4 5)

And you want tho produce the following:

'((A 1 3) (B 2 4) (C 1 5) (D 2 3) (E 1 4) (F 2 5) (A 1 3) (B 2 4) (C 1 5) (D 2 
3) ...)

As you can see each element of the sublist corresponds to the list-ref of the 
modulo n (length sublist) as n proceeds from 0 to  some maximum value. I’ve 
created a function that does exactly this, but … I’ve no idea what this process 
might be called. As they say, the naming of cats, and all that.Does this sort 
of mapping have a formal name?

Thanks!
Kevin

-- 
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/C34265FD-5370-47BD-B5AE-9FC75BEEFA8D%40gmail.com.


Re: [racket-users] [racket users] list question

2021-02-25 Thread Kevin Forchione



> On Feb 25, 2021, at 10:12 AM, Norman Gray  wrote:
> 
> 
> I think this is called 'zip', or a convolution [1].  The variant you describe 
> is (effectively) with circular lists, but seems to be the same principle.
> 
> ...and I see that, with that name in hand, SRFI/1 does indeed have a zip 
> procedure, which works with circular lists.

Thanks, Norman! Looks like “zip” is the right name for the general process, and 
now that I can browse the docs for it there seems to be several flavors in 
various library modules, depending on creator intention.  I’ve generalized mine 
a bit to fit intention and some of theirs. 

(define/contract (zip #:length (len max) . lsts)
  (->* () (#:length (or/c procedure? natural?)) #:rest (listof list?) (listof 
list?))
  (define (loop cnt (acc empty))
(cond
  [(zero? cnt) acc]
  [else
   (define n (sub1 cnt))
   (loop n (cons (map (λ (lst) (list-ref lst (modulo n (length lst 
lsts) acc))]))
  (loop (cond
  [(procedure? len)
   (apply len (map length lsts))]
[else len])))

Kevin

-- 
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/650A2841-B8F8-4802-9116-7AB9876EA901%40gmail.com.


Re: [racket-users] Macro generating macro question

2023-05-24 Thread Kevin Forchione


> On May 24, 2023, at 2:11 AM, Jens Axel Søgaard  wrote:
> 
> #lang racket
> (require (for-syntax syntax/parse
>  racket/syntax))
> 
> (define-syntax (make-id-macro stx)
>   (syntax-parse stx
> [(_ id)
>  (with-syntax ([name (format-id #'id "do-~a" #'id)]
>[ooo  #'(... ...)])
>#'(define-syntax (name stx)
>(syntax-parse stx
>  [(_ parms ooo)
>   #'(list parms ooo)])))]))
> 
> (make-id-macro foo)
> (do-foo 1 2)

Thanks! That was the fundamental concept I was missing. I don’t recall seeing 
that in the documentation, but now that I know I’ll search for that and see if 
I glossed over it somehow. 

-Kevin

-- 
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/beaa2ef6-afd2-4686-829a-390eb69f5620n%40googlegroups.com.

Beyond the Racket Users Google Group, Racket Discussions take place on 
Discourse ( https://racket.discourse.group/ ) and Discord ( 
https://discord.gg/6Zq8sH5 ). Discussion (but less active) also takes place on 
the Racket Slack https://racket.slack.com/ ( sign up at 
https://racket-slack.herokuapp.com/ ), and IRC #racket 
https://kiwiirc.com/nextclient/irc.libera.chat/#racket
--- 
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/D299A992-F57A-4050-B8DD-67DCAC468124%40gmail.com.


[racket-users] Macro generating macro question

2023-05-23 Thread Kevin Forchione
Hi guys, 
I’m stumped.  In a nutshell I want to write a macro that is passed  an id and 
will produce a macro called id that can take variable arguments. I’m sure I’m 
overlooking something fundamental. The basic form below “works” if I don’t have 
ellipsis aver the variables, but that’s not what I’m after. Here’s an example 
that is obviously wrong, but is along the lines of what I’m looking for:

#lang racket


(require (for-syntax syntax/parse
 racket/syntax))

(define-syntax (make-id-macro stx)
  (syntax-parse stx
[(_ id)
 (with-syntax ([name (format-id #'id "do-~a" #'id)])
   #'(define-syntax (name stx)
   (syntax-parse stx
 [(_ parms ...)
  #'( list parms ...)])))]))

Any help in this and explaining why it fails would be greatly appreciated.

-Kevin

-- 
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/beaa2ef6-afd2-4686-829a-390eb69f5620n%40googlegroups.com.

Beyond the Racket Users Google Group, Racket Discussions take place on 
Discourse ( https://racket.discourse.group/ ) and Discord ( 
https://discord.gg/6Zq8sH5 ). Discussion (but less active) also takes place on 
the Racket Slack https://racket.slack.com/ ( sign up at 
https://racket-slack.herokuapp.com/ ), and IRC #racket 
https://kiwiirc.com/nextclient/irc.libera.chat/#racket
--- 
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/6BC84910-3AC4-4729-8BAA-D1488E84A54B%40gmail.com.