Re: [racket-users] macros in Racket repository

2021-05-09 Thread Tim Meehan
Thanks folks! > On May 9, 2021, at 09:38, Robby Findler wrote: > >  > Here's one way to write it in modern Racket: > > #lang racket > (require (for-syntax syntax/parse)) > > (module+ test (require rackunit)) > > (define-syntax (my-and stx) > (syntax-parse stx > [(_) #'#f] > [(_

Re: [racket-users] macros in Racket repository

2021-05-09 Thread Robby Findler
Here's one way to write it in modern Racket: #lang racket (require (for-syntax syntax/parse)) (module+ test (require rackunit)) (define-syntax (my-and stx) (syntax-parse stx [(_) #'#f] [(_ e:expr) #'e] [(_ e1:expr e2:expr ...) #'(if e1 (my-and e2 ...) #f)])) (module+ test

Re: [racket-users] macros in Racket repository

2021-05-09 Thread Jens Axel Søgaard
Hi Tim, In this case Ryan's method leads to: https://github.com/racket/racket/blob/master/racket/collects/racket/private/qq-and-or.rkt#L440 But in case you are wondering about the style used in that file: at the point where "qq-and-or.rkt" is used, none of the usual syntax tools (such as

Re: [racket-users] macros in Racket repository

2021-05-09 Thread Ryan Culpepper
Here are the three most convenient ways I know of to find that information (which is "$RACKET/collects/racket/private/qq-and-or.rkt" in this specific case): If you use DrRacket, then open a file that uses `and`, right-click on an occurrence of `and`, and choose "Open Defining File" (which changes

[racket-users] macros in Racket repository

2021-05-09 Thread Tim Meehan
Where in the repository are macros like "and" and "or" defined? I tried searching for "and" and "or" ... but you probably know how that worked out. Thanks folks! -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group

Re: [racket-users] Macros expanding to require forms

2020-11-12 Thread Veit Heller
Hello, This is very useful information, thank you! I still have trouble understanding _why_ this works, though; I guess I’m a little confused as to how the scope-flipping influences things. For instance, I don’t quite understand why the example from the docs works, but if you define the

Re: [racket-users] Macros expanding to require forms

2020-11-12 Thread Sorawee Porncharoenwase
See https://docs.racket-lang.org/reference/stxtrans.html#%28def._%28%28quote._~23~25kernel%29._syntax-local-introduce%29%29 for an example program that requires a library via a macro. On Thu, Nov 12, 2020 at 3:09 AM Veit Heller wrote: > > Hello, > > I’m suspecting I’m getting a little turned

[racket-users] Macros expanding to require forms

2020-11-12 Thread Veit Heller
Hello, I’m suspecting I’m getting a little turned around by phase levels and where `require` comes in: it seems to be impossible to write a macro that expands to a valid `require` (it doesn’t throw an error, but the functions aren’t defined either). What am I missing? At what phase level does

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

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

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

2020-10-21 Thread Ben Greenman
You can use syntax-local-value to communicate across macros. Here's an example: https://docs.racket-lang.org/syntax-parse-example/index.html?q=cross-macro#(mod-path._syntax-parse-example%2Fcross-macro-communication%2Fcross-macro-communication) On 10/21/20, Kevin Forchione wrote: > Hi

[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

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

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

2019-06-03 Thread Matthias Felleisen
> 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 :) -- You received this message because you are

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

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

2019-06-03 Thread Matthias Felleisen
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

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

2019-06-03 Thread Matthias Felleisen
#lang racket (require (for-syntax ) racket/stxparam) (define-syntax-parameter return (syntax-rules ())) (define-syntax fn (syntax-rules () [(_ (arg ...) body ...) (λ (arg ...) (let/cc fn-exit (syntax-parameterize ([return (syntax-rules () [(_ x) (fn-exit x)])])

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)

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

2019-06-03 Thread Matthias Felleisen
My code run your examples. Whay is missinng? > On Jun 3, 2019, at 11:36 AM, Kevin Forchione wrote: > > > >> On Jun 3, 2019, at 4:54 AM, Alex Knauth wrote: >> >> >> >>> On Jun 3, 2019, at 1:02 AM, Kevin Forchione wrote: On Jun 2, 2019, at 7:13 PM, Matthias Felleisen

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 > > wrote: >>> On Jun 2, 2019, at 7:13 PM, Matthias Felleisen >> > wrote: On Jun 2, 2019, at 9:41 PM, Kevin Forchione >>>

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

2019-06-03 Thread Alex Knauth
> On Jun 3, 2019, at 1:02 AM, Kevin Forchione wrote: >> On Jun 2, 2019, at 7:13 PM, Matthias Felleisen > > wrote: >>> On Jun 2, 2019, at 9:41 PM, Kevin Forchione >> > wrote: >>> >>> Hi guys, >>> I’ve been working with macros and let/cc

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

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

2019-06-02 Thread Matthias Felleisen
> On Jun 2, 2019, at 9:41 PM, Kevin Forchione 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-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)

Re: [racket-users] Macros crossing documentation-time and run-time phases

2019-03-21 Thread Matthew Flatt
At Mon, 18 Mar 2019 19:32:40 -0400, Philip McGrath wrote: > On Mon, Mar 18, 2019 at 9:14 AM Matthew Flatt wrote: > > > I wonder whether the solution is an extension of `scribble/lp2` to > > support a `require-for-chunk` form where `chunk` records any such > > imports in its context and adds then

Re: [racket-users] Macros crossing documentation-time and run-time phases

2019-03-18 Thread Philip McGrath
On Mon, Mar 18, 2019 at 9:14 AM Matthew Flatt wrote: > I wonder whether the solution is an extension of `scribble/lp2` to > support a `require-for-chunk` form where `chunk` records any such > imports in its context and adds then to the stitched-together program. > > (require-for-chunk (only-in

Re: [racket-users] Macros crossing documentation-time and run-time phases

2019-03-18 Thread Matthew Flatt
Just to make sure we're on the same page, it seems like your example fails for the same reason that #lang scribble/lp2 @(require racket/string) @(chunk <*> string-join) fails. That `require` turns out to do nothing, and there's no binding of `string-join` in the "phase" of the program is that

[racket-users] Macros crossing documentation-time and run-time phases

2019-03-18 Thread Philip McGrath
Racket makes it easy to write macros that mix run-time code with various compile-time phases, using lexical scope to refer unambiguously to the correct binding for each identifier, including bindings that are not directly exported. Macro-generating macros are a great example, in that they expand

Re: [racket-users] Macros that conditionally generate code

2019-03-07 Thread Greg Hendershott
This reminds me of a similar thread on Slack yesterday. When a macro `define`s something, it's usually better for everyone if the identifier is supplied to the macro. It's nicer for you as the macro writer because you don't need to think so hard about scope and hygiene. And it's nicer for the

Re: [racket-users] Macros that conditionally generate code

2019-03-06 Thread David Storrs
On Wed, Mar 6, 2019 at 11:31 PM Sorawee Porncharoenwase wrote: > > Isn’t this because of hygienity in general? *headdesk* Of course. Thanks, I should have recognized that. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from

Re: [racket-users] Macros that conditionally generate code

2019-03-06 Thread Sorawee Porncharoenwase
Isn’t this because of hygienity in general? For example: #lang racket (define-syntax (foo stx) (syntax-case stx () [(_) #'(define doubleup 1)])) (foo) doubleup ; unbound id doesn’t define doubleup. While the below code does: #lang racket (define-syntax (foo stx) (syntax-case stx ()

Re: [racket-users] [Racket Users] Macros and literals question

2018-09-17 Thread Matthew Butterick
> On Sep 17, 2018, at 11:57 AM, Kevin Forchione wrote: > > 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

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 > > wrote: >> >> Thanks! That’s just what I wanted. Is there a way in Racket to determine if >> a quoted symbol has an associated procedure? > > > >

Re: [racket-users] [Racket Users] Macros and literals question

2018-09-17 Thread Alexis King
> On Sep 17, 2018, at 12:21, Kevin Forchione wrote: > > 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 & >

Re: [racket-users] [Racket Users] Macros and literals question

2018-09-17 Thread Matthew Butterick
> On Sep 17, 2018, at 10:21 AM, Kevin Forchione wrote: > > 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 & >

Re: [racket-users] [Racket Users] Macros and literals question

2018-09-17 Thread Philip McGrath
It might help to know a bit more context about what you're trying to do. I think other Lisp-family languages use these terms in different ways, but in Racket it isn't usual to talk about a symbol being bound to something. A symbol is just a type of value (like an integer, a list, a vector, a

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

Re: [racket-users] [Racket Users] Macros and literals question

2018-09-16 Thread Matthew Butterick
> On Sep 16, 2018, at 2:13 PM, Kevin Forchione > 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)

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)

Re: [racket-users] [Racket Users] Macros and literals question

2018-09-15 Thread Philip McGrath
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

[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

Re: [racket-users] macros

2016-10-27 Thread Alexis King
First of all, #lang racket is not Scheme, nor does it claim to be. However, #lang r5rs does attempt to be Scheme, and it exhibits the same behavior as #lang racket in this case, so your question is still valid. I would argue that, in this case, Racket gets it right, and Bigloo and Kawa are

[racket-users] macros

2016-10-27 Thread Damien Mattei
Hi, why this does not work with DrRacket: #lang racket (define-syntax then (syntax-rules () ((_ ev) ev) ((_ ev ...) (begin ev ... (define-syntax else (syntax-rules () ((_ ev) ev) ((_ ev ...) (begin ev ... (if #f (then 1 2 3) (else 3

Re: [racket-users] Macros that use with-handlers

2016-07-17 Thread Jack Firth
On Saturday, July 16, 2016 at 7:06:10 PM UTC-4, David K. Storrs wrote: > So, if one should prefer functions, what is a good place to use > macros? When people talk about why LISP/Scheme/Racket are the most > powerful languages, they inevitably mention macros and continuations. > What is a good

Re: [racket-users] Macros that use with-handlers

2016-07-16 Thread David Storrs
I see. Okay, thanks for clarifying. On Sat, Jul 16, 2016 at 8:05 PM, Alex Knauth wrote: > >> On Jul 16, 2016, at 7:18 PM, David Storrs wrote: >> >> Wow, that is a lot of problems. Thanks for taking the time to >> comment; this was in large part an

Re: [racket-users] Macros that use with-handlers

2016-07-16 Thread Alex Knauth
> On Jul 16, 2016, at 7:18 PM, David Storrs wrote: > > Wow, that is a lot of problems. Thanks for taking the time to > comment; this was in large part an effort to learn macros, so it's > helpful to get this kind of feedback. > On Sat, Jul 16, 2016 at 2:48 PM, Alex

Re: [racket-users] Macros that use with-handlers

2016-07-16 Thread David Storrs
Wow, that is a lot of problems. Thanks for taking the time to comment; this was in large part an effort to learn macros, so it's helpful to get this kind of feedback. On Sat, Jul 16, 2016 at 2:48 PM, Alex Knauth wrote: > >> On Jul 16, 2016, at 2:16 PM, David Storrs

Re: [racket-users] Macros that use with-handlers

2016-07-16 Thread David Storrs
On Sat, Jul 16, 2016 at 2:48 PM, William J. Bowman wrote: > To address the immediate problem, this `procedure?` test will always return > `#f`, since `#'pred` is a > syntax object and not a procedure. You need to do `(procedure? (syntax->datum > #'pred))`. Similarly >

Re: [racket-users] Macros that use with-handlers

2016-07-16 Thread David Storrs
On Sat, Jul 16, 2016 at 2:48 PM, Alexis King wrote: > Of course, this makes sense, given that macros operate entirely at > compile-time. What you really want here is a function, not a macro. You > can write a simple function that will accept a procedure or a string and >

Re: [racket-users] Macros that use with-handlers

2016-07-16 Thread Alex Knauth
> On Jul 16, 2016, at 2:16 PM, David Storrs wrote: > > I'm trying to write a macro to test expected exceptions. I'd like it > to have the following forms: > > (throws exception-generator-function proc msg) > (throws exception-generator-function string msg) > > Where

Re: [racket-users] Macros that use with-handlers

2016-07-16 Thread 'William J. Bowman' via Racket Users
On Sat, Jul 16, 2016 at 02:16:20PM -0400, David Storrs wrote: > I saw the #:when keyword for patterns and thought that would do what I > needed. The following code seems like it should work, but it doesn't. > What am I missing? > > > (define-syntax (throws stx) > (syntax-parse stx >

Re: [racket-users] Macros that use with-handlers

2016-07-16 Thread Alexis King
I don’t think you want to use a macro to do this. You could detect, at compile-time, whether or not the provided argument is a string within the macro. The best way to do this would probably be to use the “str” syntax class, which detects strings within a syntax-parse pattern. However, this has a

[racket-users] Macros that use with-handlers

2016-07-16 Thread David Storrs
I'm trying to write a macro to test expected exceptions. I'd like it to have the following forms: (throws exception-generator-function proc msg) (throws exception-generator-function string msg) Where 'proc' would be something like exn:fail? and 'string' would be matched against the message

Re: [racket-users] macros within expressions.

2016-04-06 Thread Alex Knauth
> On Apr 6, 2016, at 8:29 PM, Matthew Butterick wrote: > So you can repair your macro by matching to `y-coord` as a pattern: > > ;;; > > #lang racket > (require rackunit) > > (define-syntax y-coord > (syntax-id-rules () > [y-coord point-y])) > > (struct

Re: [racket-users] macros within expressions.

2016-04-06 Thread Matthew Butterick
> Expanding `y-coord` by itself leads to the error. I've tripped over this, so just to elaborate slightly. `syntax-id-rules` will work, but your current macro: ;;; (define-syntax y-coord (syntax-id-rules (map) [(map y-coord lst) (map (lambda (p)

Re: [racket-users] macros within expressions.

2016-04-06 Thread Vincent St-Amour
Adding `(define y-coord points-y)` should make the original example work as-is. Vincent On Wed, 06 Apr 2016 15:45:56 -0500, Daniel Prager wrote: > > (map point-y points) gives the expected result without recourse to a > macro. > > Or is y-coord intended as a simplified example of something

Re: FW: [racket-users] macros within expressions.

2016-04-06 Thread Benjamin Greenman
This is "bad syntax" for the same reason that `(map or '())` is "bad syntax". When the macro expander sees `(map y-coord points)`, it recognizes `map` as a variable binding and then tries expanding each argument to `map`. Expanding `y-coord` by itself leads to the error. You could instead define

FW: [racket-users] macros within expressions.

2016-04-06 Thread Jos Koot
Oops, forgot to include the users list. _ From: Jos Koot [mailto:jos.k...@gmail.com] Sent: miércoles, 06 de abril de 2016 23:03 To: 'Richard Adler' Subject: RE: [racket-users] macros within expressions. You don't need a macro here. Why not simply: (map point-y points) May be your

Re: [racket-users] macros within expressions.

2016-04-06 Thread Daniel Prager
(map point-y points) gives the expected result without recourse to a macro. Or is y-coord intended as a simplified example of something else? Dan -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop

[racket-users] macros within expressions.

2016-04-06 Thread 'Richard Adler' via Racket Users
I am trying to use a macro, y-coord, in the following way: (struct point (x y)) (define points (list (point 25 25) (point 33 54) (point 10 120)) (map y-coord points) I am expecting the result: '(25 54 120) and the error is "y-coord: bad syntax in: y-coord Here is the macro: (define-syntax

Re: [racket-users] Macros outline

2016-02-05 Thread Gavin McGimpsey
Thanks, Greg! I appreciated that approach – and ordered things pretty much the same way here. On Thursday, February 4, 2016 at 7:17:37 PM UTC-7, Greg Hendershott wrote: > I really like it! > > Compared to FoM, you get to the point more quickly and clearly. > > (FoM is closer to that genre

Re: [racket-users] Macros outline

2016-02-04 Thread Greg Hendershott
I really like it! Compared to FoM, you get to the point more quickly and clearly. (FoM is closer to that genre where someone takes notes on their first 24 hours trying to understand a new language. (Except in my case with macros it felt like months not hours.)) I hope you do expand it. On

Re: [racket-users] Macros outline

2016-02-03 Thread Asumu Takikawa
Hi Gavin, On 2016-02-03 11:37:39 -0800, Gavin McGimpsey wrote: > I'd appreciate any feedback! This is very nice and concise! Thanks for writing it. If you do expand it, it might be worth mentioning that the macro stepper lets you debug macros. And if you expand with info on `syntax-parse`, you

[racket-users] Macros outline

2016-02-03 Thread Gavin McGimpsey
I've been picking up Racket here and there, and have spent the last little while learning about macros. The Reference and Guide are comprehensive, of course, and Greg Hendershott's Fear of Macros is an excellent introduction. I found that it took me a little to see how each of the pieces fit