Re: [racket-users] Re: scribble: referencing two identifiers with the same name?

2021-05-03 Thread Sam Caldwell
Ah, I meant what happens when I open up my scribble file in DrRacket and
press the "Scribble HTML" button. Maybe it would be more accurate to
describe that as a plugin than DrRacket itself?

-Sam Caldwell

On Mon, May 3, 2021 at 11:24 AM Robby Findler 
wrote:

> On Mon, May 3, 2021 at 10:19 AM Sam Caldwell  wrote:
>
>> When I first ran Ryan's example, the reference to `racket:let` did not
>> resolve to the proper link. After further investigating, this appears to be
>> due to scribble's default behavior of not loading extra cross-referencing
>> information [1]. If instead of `raco scribble`, I run `raco scribble +m`
>> the link does resolve to the proper location. It also appears that DrRacket
>> uses the +m option by default.
>>
>>
> Just a minor point of clarification: DrRacket uses the documentation built
> by `raco setup`; it doesn't build the docs itself. This is the same build
> of the docs you see with `raco docs`.
>
> Robby
>
>

-- 
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/CALuKBHvJFmaJB9nf9%2BSDRAR6HUNa2pXeC0eaRfJ7VQ1quiC4_w%40mail.gmail.com.


Re: [racket-users] Re: scribble: referencing two identifiers with the same name?

2021-05-03 Thread Sam Caldwell
When I first ran Ryan's example, the reference to `racket:let` did not
resolve to the proper link. After further investigating, this appears to be
due to scribble's default behavior of not loading extra cross-referencing
information [1]. If instead of `raco scribble`, I run `raco scribble +m`
the link does resolve to the proper location. It also appears that DrRacket
uses the +m option by default.

So my current understanding is that there is no barrier to linking to other
forms if you rename them `for-label`, but if I want the same name to link
to different parts of the documentation I need to do something like the
Typed Racket example.

-Sam Caldwell

[1]
https://docs.racket-lang.org/scribble/running.html?q=scribble#%28part._xref-flags%29

On Sat, May 1, 2021 at 2:00 PM Ryan Kramer  wrote:

> Using the prefix should still link correctly. When I run the following
> program, it links to section 3.9 of the Racket Reference where `let` is
> defined. Does your link go somewhere else?
>
> ```
> #lang scribble/manual
>
> @(require (prefix-in racket: (for-label racket/base)))
>
> @defform[(let ([id expr] ...) body ...)]{
>  The same behavior as @(racket racket:let).
> }
> ```
>
> If you really want to remove the prefix, I don't know of any easier way
> than what you've already found. However, as a reader of the documentation I
> don't mind seeing the prefix. In fact, I think I would prefer to see it
> because then I can make a very good guess that it is talking about Racket's
> `let` without hovering or clicking the link.
>
> On Friday, April 30, 2021 at 11:01:20 AM UTC-5 sa...@ccs.neu.edu wrote:
>
>> Is there an easy way to refer to two different identifiers with the same
>> name when writing scribble documentation?
>>
>> For example, let's say I have a language with a `let` binding that
>> operates more or less the same as racket's `let`. I wanted to write
>> something like this:
>>
>> ```
>> @(require (prefix-in racket: (for-label racket/base)))
>>
>> @defform[(let ([id expr] ...) body ...){
>> The same behavior as @racket[racket:let].
>> }
>> ```
>>
>> This doesn't seem to work; the reference to racket's `let` ends up
>> including the `racket:` prefix and doesn't seem to resolve to the
>> appropriate link.
>>
>> I looked at Typed Racket's docs to see how it manages this problem, and
>> found the following pattern:
>>
>> ```
>> @(module def-racket racket/base
>>(require (for-label racket/base) scribble/manual)
>>(define let-id (racket let))
>>(provide let-id))
>>
>> @(require 'def-racket)
>>
>> @defform[(let ([id expr] ...) body ...){
>> The same behavior as @|let-id|.
>> }
>> ```
>>
>> source:
>> https://github.com/racket/typed-racket/blob/master/typed-racket-doc/typed-racket/scribblings/reference/special-forms.scrbl
>>
>> So my question is, is there an easier/more direct way to accomplish this
>> (perhaps since these typed racket docs were written)?
>>
>> It also looks like this pattern could be captured by a macro---has
>> someone written that already?
>>
>> Thanks,
>> Sam Caldwell
>>
> --
> 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/334007f4-0632-4814-8d22-9ad56f650d21n%40googlegroups.com
> <https://groups.google.com/d/msgid/racket-users/334007f4-0632-4814-8d22-9ad56f650d21n%40googlegroups.com?utm_medium=email_source=footer>
> .
>

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


[racket-users] scribble: referencing two identifiers with the same name?

2021-04-30 Thread Sam Caldwell
Is there an easy way to refer to two different identifiers with the same
name when writing scribble documentation?

For example, let's say I have a language with a `let` binding that operates
more or less the same as racket's `let`. I wanted to write something like
this:

```
@(require (prefix-in racket: (for-label racket/base)))

@defform[(let ([id expr] ...) body ...){
The same behavior as @racket[racket:let].
}
```

This doesn't seem to work; the reference to racket's `let` ends up
including the `racket:` prefix and doesn't seem to resolve to the
appropriate link.

I looked at Typed Racket's docs to see how it manages this problem, and
found the following pattern:

```
@(module def-racket racket/base
   (require (for-label racket/base) scribble/manual)
   (define let-id (racket let))
   (provide let-id))

@(require 'def-racket)

@defform[(let ([id expr] ...) body ...){
The same behavior as @|let-id|.
}
```

source:
https://github.com/racket/typed-racket/blob/master/typed-racket-doc/typed-racket/scribblings/reference/special-forms.scrbl

So my question is, is there an easier/more direct way to accomplish this
(perhaps since these typed racket docs were written)?

It also looks like this pattern could be captured by a macro---has someone
written that already?

Thanks,
Sam Caldwell

-- 
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/CALuKBHsXBQAB_Thyp9Y8PLSosXSiLWN5fUHrLBBuDF333vXfxw%40mail.gmail.com.


Re: [racket-users] Help implementing an early return macro

2020-10-28 Thread Sam Caldwell
Ryan's solution is almost certain to be nicer, but if you do find yourself
needing internal definition contexts now or in the future, this is similar
to a case I ran into while adding `define` to a language implemented with
Turnstile.

I wrote a blog post outlining the solution [1], which I believe implements
the kind of local-expand loop asked about. You can skip to the "Internal
Definition Contexts" section if you don't care about the particulars of
Turnstile. There's some extra machinery for dealing with Turnstile-specific
things, but they should be pretty easy to remove and the basic ideas apply.
I didn't include splicing begins in the post, but it's comparatively
straightforward and in the actual implementation [2].

-Sam Caldwell

[1]
http://prl.ccs.neu.edu/blog/2018/10/22/defining-local-bindings-in-turnstile-languages/
[2]
https://github.com/tonyg/syndicate/blob/a6fc1f20e41fba49dc70d38b8c5047298e4b1811/racket/typed/core-types.rkt#L1220

On Wed, Oct 28, 2020 at 9:28 AM Ryan Culpepper 
wrote:

> This is a nice example of a macro design pattern that I think of as
> "partial expansion with trampolining". You don't need to deal with the
> internal definition context API, because you can return definitions to the
> macro expander, let it handle their interpretation, and then resume your
> work. Here's an implementation sketch:
>
> 1. First, make sure you're in an internal definition context:
> (guarded-block form ...) => (let () (guarded-block* form ...)). The
> guarded-block* helper macro has the invariant that it is always used in
> internal definition context.
> 2. If guarded-block* has at least one form, it partially expands it, using
> a stop list containing guard and Racket's primitive syntactic forms. Then
> it analyzes the partially-expanded form:
> - If it is a begin, it recurs with the begin's contents appended to the
> rest of its argument forms.
> - If it is a define-values or define-syntaxes form, it expands into (begin
> defn (guarded-block* form-rest ...)). The macro expander interprets the
> definition, adds it to the environment, etc. Then guarded-block* resumes
> with the rest of the forms (in the same definition context).
> - If it is a guard form, then you transform its contents and the rest of
> the forms into a cond expression, with a recursive call in the right place.
> - Anything else, assume it's an expression, and trampoline the same as for
> a definition.
>
> Also, because you're calling local-expand, you should disarm the result of
> local-expand and then call syntax-protect on the syntax you produce. If you
> don't disarm, then you might get "cannot use identifier tainted by macro
> transformer" errors. If you don't call syntax-protect, your macro can be
> misused to circumvent other macros' protection.
>
> I've attached an implementation.
>
> Ryan
>
>
> On Wed, Oct 28, 2020 at 11:54 AM Jack Firth  wrote:
>
>> So I'm a little tired of writing code like this:
>>
>> (define x ...)
>> (cond
>>   [(take-shortcut? x) (shortcut x)]
>>   [else
>>(define y (compute-y x))
>>(cond
>> [(take-other-shortcut? x y) (other-shortcut x y)]
>> [else
>>  (define z ...)
>>  (cond ...)])])
>>
>> That is, I have some logic and that logic occasionally checks for
>> conditions that make the rest of the logic irrelevant, such as an empty or
>> false input or something else that should trigger an early exit. Each check
>> like this requires me to write a cond whose else clause wraps the
>> remainder of the body, leading to an awkward nesting of cond forms. I
>> don't have this issue when the early exits involve raising exceptions: in
>> those cases I can just use when and unless like so:
>>
>> (define x ...)
>> (unless (passes-check? x) (raise ...))
>> (define y ...)
>> (unless (passes-other-check? x y) (raise ...))
>> (define z ...)
>> ...
>>
>> I'm aware of a few macros in the racket ecosystem that try to solve this
>> problem. For example, Jay wrote a blog post
>> <http://jeapostrophe.github.io/2013-11-12-condd-post.html> that creates
>> a condd form that's like cond but allows embedded definitions using a
>> #:do keyword. I've also seen various approaches that use escape
>> continuations to implement the early exit. There's drawbacks I'm not happy
>> about however:
>>
>>-
>>
>>For cond-like macros that allow embedded definitions, it looks too
>>different from regular straight-line Racket code. I like my function 
>> bodies
>>to be a sequence of definitions and expressions, with minimal nesting, 
>> just
>>like the when and unless version above. I 

Re: [racket-users] Typed Syndicate Status

2020-03-10 Thread Sam Caldwell
Er, jumped the gun a bit;


On Tue, Mar 10, 2020 at 10:25 AM Ray Racine  wrote:
>
>> For a new project with Syndicate I'd like to jump up to typed/syndicate
>> if possible even if it is a little bit "early".  As expected it looks like
>> PLT's approach to typing dataspaces, tuples spaces, actors and messaging
>> looks novel and impressive.
>>
>> Yesterday with a few tweaks here and there I have typed/syndicate
>> compiling and running 1 or 2 of the examples.  The tweaks that appear to be
>> necessary are to sync up typed/syndicate with the latest Turnstile.
>>
>
I would be very interested to hear how you are using Syndicate and what
your experience has been like, if you wouldn't mind sharing. Do you have
any projects on github that are using it?


> Glancing at the example code I expect to use the extended language
>> capability offered via #lang typed/syndicate/roles. The project is an
>> opensource one of a personal nature and is fine with bug reports,
>> workarounds and hiccups assuming typed/syndicate work is still "active".
>>
>> Questions:
>>
>>1. Is #lang typed/syndicate/roles more or less ready for beta code
>>use?
>>
>> More or less, yes. I can anticipate a couple of potential issues:
- There is no integration with Typed Racket.
- The type system does all its work during macro expansion and is generally
un-optimized, so you may notice longer compilation times.
- While there is support for interoperating with untyped syndicate and
untyped code in general, no contracts are generated to ensure safety.
- There is no documentation (though I actually started working on some
this morning).

>
>>1. Is it active and maintained?
>>
>> Yes! I am currently developing typed syndicate.

>
>>1. Can the Syndicate's git repo typed branch be sync'd up with the
>>current Turnstile and Racket release?[1]
>>
>> Yes; in fact I think it's about time I integrated typed syndicate into
the master branch so you shouldn't need to fiddle with those.

I'm generally happy to answer any question you may have about typed or
untyped Syndicate, no matter how small, and look into any issue that needs
to be addressed. Feel free to email me directly or open issues on github.

Cheers,
Sam Caldwell

-- 
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/CALuKBHsWpTRmvrRCVqXBAigWe6_o4YZW8UiVYk8%3DOVfrkecm6w%40mail.gmail.com.


Re: [racket-users] Typed Syndicate Status

2020-03-10 Thread Sam Caldwell
hi Ray,



On Tue, Mar 10, 2020 at 10:25 AM Ray Racine  wrote:

> For a new project with Syndicate I'd like to jump up to typed/syndicate if
> possible even if it is a little bit "early".  As expected it looks like
> PLT's approach to typing dataspaces, tuples spaces, actors and messaging
> looks novel and impressive.
>
> Yesterday with a few tweaks here and there I have typed/syndicate
> compiling and running 1 or 2 of the examples.  The tweaks that appear to be
> necessary are to sync up typed/syndicate with the latest Turnstile.
>
> Glancing at the example code I expect to use the extended language
> capability offered via #lang typed/syndicate/roles. The project is an
> opensource one of a personal nature and is fine with bug reports,
> workarounds and hiccups assuming typed/syndicate work is still "active".
>
> Questions:
>
>1. Is #lang typed/syndicate/roles more or less ready for beta code use?
>2. Is it active and maintained?
>3. Can the Syndicate's git repo typed branch be sync'd up with the
>current Turnstile and Racket release?[1]
>
> [1] I can help with small compilation issue patches if there is someone
> currently active in typed/syndicate to receive them.
>
>
>

-- 
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/CALuKBHu6ZO8%3DUJ70XetRs-SuduQx-xzOSSQC6HR16BpvGWKM3A%40mail.gmail.com.


Re: [racket-users] Re: resources on PL design

2019-06-30 Thread Sam Caldwell
I'd add the HOPL proceedings to the mix:

https://hopl4.sigplan.org/track/hopl-4-papers#History-of-HOPL

Where the designers of languages often talk about their motivations, why
they made particular decisions, and what kinds of effects those decisions
seemed to have.

On Sun, Jun 30, 2019 at 7:24 AM Stephen De Gabrielle <
spdegabrie...@gmail.com> wrote:

> I've added EOPL and some others. I obviously haven't read all these, but
> have added them because they refer to PL *design* or *implementation* in
> description or TOC.
> Thanks to those who responded.
>
> https://github.com/racket/racket/wiki/Creating-Languages#Books
> Books
>
>- Programming Languages: Application and Interpretation
> by Shriram
>Krishnamurthi (see the PLAI Typed Language #lang plai-typed
>)
>- Essentials of Programming Languages  by
>Daniel P. Friedman and Mitchell Wand (Publisher
>
> 
>)
>- Design Concepts in Programming Languages
> by
>Franklyn Turbak, David Gifford and Mark Sheldon
>- Programming Language Pragmatics by Michael L. Scott
>- Practical Foundations for Programming Languages by Professor Robert
>Harper
>- Principles of Programming Languages: Design, Evaluation, and
>Implementation by Bruce J. MacLennan
>- Advanced Programming Language Design
>
> 
>  by
>Raphael Finkel
>- Lisp in Small Pieces
> by Christian
>Queinnec and covers *'semantics and the implementation of the whole
>Lisp family of languages, namely Lisp, Scheme and related dialects. It
>describes 11 interpreters and 2 compilers'*
>- Structure and Interpretation of Computer Programs - teaches computer
>science by teaching students how to implement interpreters. (see also the
>Racket #lang sicp designed to go with the book
>)
>
>
>
> On Fri, Jun 28, 2019 at 1:13 PM Stephen De Gabrielle <
> spdegabrie...@gmail.com> wrote:
>
>> Hi,
>>
>> I'm looking for resources on PL *design*., i.e. deciding what to make and
>> how to assess/test those design decisions,  before moving onto how to make
>> it.
>>
>> Any additions, opinions or advice appreciated:
>>
>> Programming Languages: Application and Interpretation by Shriram
>> Krishnamurthi  https://www.plai.org/
>>
>> Programming Language Pragmatics by Michael L. Scott
>>
>> Practical Foundations for Programming Languages by Professor Robert Harper
>>
>> Design Concepts in Programming Languages (The MIT Press) by Franklyn
>> Turbak
>>
>> Kind regards,
>>
>>
>>
>> Stephen
>>
>>
>>
>> * the languages are not important but FYI: Cobol, vb6, vb.net, C/C++,
>> PHP, Python, c#, Java, MUMPS & JavaScript.
>>
> --
> 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/CAGHj7-KOEDGxyXfQ3m2p%3D1rAHsaqTWRBHYGfmriv_Lq%3DpXdPAA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] Strip the lexical context from an identifier

2019-02-22 Thread Sam Caldwell
You can also do this with syntax-local-introduce to remove x's use-site
scope*:

#lang racket

(require (for-syntax syntax/parse))

(define-syntax (my-macro stx)
   (syntax-parse stx
 [(_ x:id)
  #:with x- (syntax-local-introduce #'x)
  #'(lambda (a b) x-)]))

((my-macro a) 1 2)
;; 1

((my-macro b) 1 2)
;; 2

(define x 3)
((my-macro x) 1 2)
;; 3



-Sam

* well, I think that's what's going on.

On Fri, Feb 22, 2019 at 1:21 PM Matthias Felleisen 
wrote:

>
>
> > On Feb 22, 2019, at 1:08 PM, Stefano Lande  wrote:
> >
> > Dear all,
> >
> > first of all, I might being misusing the terminology. Sorry about it.
> >
> > I would like to write a macro that gets an identifier and return its
> value in the new lexical scope created by the macro.
> > For example:
> >
> > > (define-syntax (my-macro stx)
> >(syntax-parse stx
> >  [(_ x:id)  #'(lambda (a b) x) ]))
> >
> >
> > > ((my-macro a) 1 2)
> > 1
> >
> > >((my-macro b) 1 2)
> > 2
> >
> >
> >
> > my-macro as above of course would not work. Is possible to receive an
> identifier, strip the lexical context, and evaluate it in the context of
> (lambda (a b) body) ?
>
>
> Here is one way to get your macro:
>
> #lang racket
>
> (require (for-syntax syntax/parse))
> (require (for-syntax racket/syntax))
>
> (define-syntax (my-macro stx)
>   (syntax-parse stx
> [(_ x:id)
>  #:with a #'a
>  #:with y (datum->syntax #'a (syntax-e #'x))
>  #`(lambda (a b) y)]))
>
> [(my-macro a) 1 2]
> [(my-macro b) 1 2]
> (define x 3)
> [(my-macro x) 1 2]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] Apparent Datalog error?

2018-01-31 Thread Sam Caldwell
Your definition of `ancestor` is one or two steps of parentage:

> ancestor(A, B) :- parent(A, B).
> ancestor(A, B) :-
parent(A, C),
parent(C, B).

I suspect you want one of those lines to appeal to the `ancestor` relation
to allow longer chains.

- Sam Caldwell

On Wed, Jan 31, 2018 at 1:53 PM, Kevin Forchione <lyss...@gmail.com> wrote:

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

-- 
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] Alternatives to DrRacket

2017-11-27 Thread Sam Caldwell
documentation (albeit limited) on the macro stepper:
http://docs.racket-lang.org/macro-debugger/index.html#%28part._.Using_the_.Macro_.Stepper%29

You can also find `expand/step` there, which I find to be a very useful
complement to using DrRacket to step through the expansion of an entire
module.

- Sam Caldwell

On Mon, Nov 27, 2017 at 11:33 AM, Damien MATTEI <damien.mat...@unice.fr>
wrote:

> Le Monday 27 November 2017 05:18:02 pm David Storrs, vous avez écrit :
>
> >
> > > 2. The macro stepper is extremely handy when it works, and being able
> to
> > > inspect syntax objects in the interactions pane is wonderful when the
> > > macro stepper doesn't work.
> >
> > Offtopic:  This is the one big feature that I've tried DrRacket for,
> > but I've never been able to make it work. Everything gets reduced to
> > lambdas instead of more high-level forms so that long before I
> > actually see anything useful I get a giant mess.   Maybe I don't
> > understand it well enough, or maybe there's something I need to do
> > differently with it?  I was expecting to just keep clicking the 'step'
> > button; is there any sort of context or etc that I need to establish
> > first?
> >
>
> not easy to use, i never succeed to use it too , any documentation
> somewhere about the macro-stepper use?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] Redex v6.4 "broke" LambdaJS

2017-09-06 Thread Sam Caldwell
History behind this change:
https://groups.google.com/d/msg/racket-users/1SVVqsg4ARQ/vVxKiAvaAQAJ
Relevant commit:
https://github.com/racket/redex/commit/cbb2d88b98fb814325f0d4ee468e1abaf4f6c3a7

So changing e_1 and e_2 to be anything that is *not* a non-terminal in your
model should do the trick.

-Sam Caldwell

On Wed, Sep 6, 2017 at 2:39 PM, Ben Greenman <benjaminlgreen...@gmail.com>
wrote:

> I think it'll work if you delete the underscores, e.g. change "e_1" to
> "e1".
>
> On Wed, Sep 6, 2017 at 2:22 PM, <natasha_da...@brown.edu> wrote:
>
>> (For some reason the mail I sent to usersracket-lang.org last week
>> never made it to the Google Group, so I'm posting directly...)
>>
>> Hello,
>>
>> I'm a 2nd year PhD student working with Shriram Krishnamurthi on
>> improving Redex's testing/checking performance and capabilities.
>>
>> I was looking to use LambdaJS (http://cs.brown.edu/research/
>> plt/dl/jssem/v1/) as a case study, but unfortunately jscore.ss does not
>> compile under the latest version of Redex.
>>
>> The shortcut used in the eval reduction relation
>> ...
>> with
>>[(--> (σ (in-hole E e_1)) (σ (in-hole E e_2)))
>> (==> e_1 e_2)]))
>> now throws an error "reduction-relation: shortcut name may not be a
>> non-terminal in: e_1."
>>
>> I believe this was caused by the following change (
>> https://github.com/racket/redex/blob/master/redex-lib/redex/HISTORY.txt)
>> in Redex v6.4:
>>
>> changed shortcuts in --> so that non-terminals are no
>> longer allowed for the names in the shortcut "parameters"
>> These shortcut names were never constrained to actually be
>> non-terminals, so this change is intended entirely to be
>> able to give a helpful error message in an attempt to avoid
>> confusion
>>
>> As a Redex novice, I'm failing to avoid confusion in this case. Any
>> advice on a simple way to change the shortcut / reduction relation to
>> respect this change in Redex is greatly appreciated.
>>
>> Thanks for the help!
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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] Expanding a macro into multiple syntax objects (Defining two things with one macro)

2017-06-22 Thread Sam Caldwell
Are you sure that `begin` doesn't suffice for your needs? It has a somewhat
unintuitive scoping behavior. From the docs [1]

The begin form is special at the top level, at module level, or as a body
after only internal definitions. In those positions, instead of forming an
expression, the content of begin is spliced into the surrounding context.

Example:

> (let ([curly 0])
(begin
  (define moe (+ 1 curly))
  (define larry (+ 1 moe)))
(list larry curly moe))

'(2 0 1)

- Sam Caldwell

[1] http://docs.racket-lang.org/guide/begin.html

On Thu, Jun 22, 2017 at 3:40 PM, Sam Waxman <samwax...@gmail.com> wrote:

> Hello,
>
> It's simple enough to write a macro that defines something.
>
> (define-syntax-rule (my-define name binding)
>(define name binding))
>
> But what if I would like to define multiple things? I.e.
>
> (define-syntax-rule (my-multiple-define name ... binding ...)
>(define name binding) ...)
>
> The above is no good, because define-syntax-rule expects only one body to
> be returned, not multiple. Wrapping the defines in begin wouldn't work,
> because then they'd only be able to be accessed in the scope of that begin
> (when, in actuality, I want the rest of the code to access them, like they
> would be able to in the first example).
>
> Similarly, if I "upgrade" the syntax-rule to define-syntax, we run into
> the same problems. I thought that the following would work,
>
> (define-syntax (my-multiple-define stx)
>(syntax-case stx ()
>  [(_ name1 name2 binding1 binding2)
>#'(define name1 binding1)
>#'(define name2 binding2)]))
>
> but it looks like this only returns the last syntax object, not both of
> them.
>
> (Note, my actual goal here is to define something, then define a syntax
> rule afterwards like
>
> (define-syntax (my-multiple-define stx)
>(syntax-case stx ()
>  [(_ x y z)
>#'(define x y)
>#'(define-syntax-rule (z *stuff*)
>*some random body to the syntax-rule*)]))
>
> , so the solution of using define-values to do all the defines in one step
> won't work for me.)
>
> I'd be satisfied either with knowing how to make a macro expand into
> multiple syntax objects (so that one macro can expand into both defines),
> or with someone letting me know how to define something, then define a
> syntax rule afterwards using only one syntax object (like wrapping them in
> a begin but that bumps the definitions inside to the outer scope).
>
> Many thanks in advance!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] How to find code in the racket distro

2017-06-20 Thread Sam Caldwell
Using github search (going to https://github.com/racket/racket and then
typing in string-titlecase to the 'search this repository' bar) I was able
to quickly find this snippet in string.c:

scheme_add_global_constant("string-titlecase",
scheme_make_immed_prim(string_titlecase,
   "string-titlecase",
   1, 1),

which suggests to me that string-titlecase is the name of something called
string_titlecase.

I then searched the repository for "string_titlecase" which pointed me back
to string.c

Searching the string.c file for string_titlecase shows that it is a
particular incantation of string_recase which is also in the file.

I'm not sure if finding other bits of the implementation would be as
seamless but it's worth a try next time you're looking for something!

- Sam Caldwell

On Tue, Jun 20, 2017 at 2:00 PM, Stephen De Gabrielle <
spdegabrie...@gmail.com> wrote:

> Hi
>
> There  was a recent question on the list about how to capitalise the first
> letter of a string.
>
> There were a number of good approaches, but I thought I would try look for
> the implementation of string-titlecase.
>
> I found it surprisingly difficult despite having the search for code
> functionality and the syntax highlighting.  In the end I gave up and went
> to bed. :(
>
> Does anyone have any suggestions about how to find definitions of core
> functions?
>
> Kind regards,
>
> Stephen
>
>
> --
> Kind regards,
> Stephen
> --
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] RacketCon Code of Conduct

2017-06-16 Thread Sam Caldwell
I agree that we should have one.

- Sam Caldwell

On Fri, Jun 16, 2017 at 2:50 PM, Stephen De Gabrielle <
spdegabrie...@gmail.com> wrote:

> Awesome. (It's an opinion)
>
> On Fri, 16 Jun 2017 at 19:48, Alexis King <lexi.lam...@gmail.com> wrote:
>
>> +1 from me. I think the Strange Loop CoC is a good one to emulate.
>>
>> > On Jun 16, 2017, at 11:44 AM, Leif Andersen <l...@leifandersen.net>
>> > wrote:
>> >
>> > RacketCon 2017 should have a code of conduct, as pointed out by Claire
>> > on twitter [1], and I absolutely agree. It doesn't have to be anything
>> > fancy, and can be a fairly standard one.
>> >
>> > Although we are not co-located with Strange Loop this year, they have
>> > a fairly sensible one that we could use [2], which is adapted from the
>> > one from the geek feminism wiki [3].
>> >
>> > Does anyone have any opinions on what we use? I would also be happy
>> > to add it to the RacketCon web page.
>> >
>> > [1]: https://twitter.com/chckadee/status/874345544977707008
>> > [2]: https://www.thestrangeloop.com/policies.html
>> > [3]: https://geekfeminism.org/about/code-of-conduct/
>> >
>> > ~Leif Andersen
>>
>> --
>> 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.
>>
> --
> Kind regards,
> Stephen
> --
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] How to apply side effects to all elements in a list

2017-03-22 Thread Sam Caldwell
2thdp/image isn't effectful; images are values. You need to combine the
image you get from rendering one bear with the image you get from rendering
the rest of the list. You can do so using one of the combiners provided by
the library:

(combiner-of-choice (render-bear (first bears))
 (render-bears (rest bears)))

(possibly with some extra arguments thrown in)

- Sam Caldwell

On Wed, Mar 22, 2017 at 3:45 PM, Angus <anguscom...@gmail.com> wrote:

> I am a bit stuck on rendering images in a list.
>
> Here is my code below.
>
> (require 2htdp/image)
>
> (define-struct bear-state (x y rotation size))
>
> (define MTS (empty-scene WIDTH HEIGHT))
>
> BEAR-IMAGE is just a graphic - of a bear.
>
> (define (render-bear b)
>   (place-image (scale (bear-state-size b) (rotate (bear-state-rotation b)
> BEAR-IMAGE))  (bear-state-x b) (bear-state-y b) MTS))
>
>
>
> (define (render-bears bears)
>   (cond [(empty? bears) (place-image (square 0 "outline" "white") 0 0 MTS)]
> [else
>   (render-bear (first bears))   ; can render 1 bear
>  (render-bears (rest bears))]))
>
>
> render-bear works but I can't get render-bears to work.  What am I doing
> wrong? Any hints?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] Stickers!

2017-01-24 Thread Sam Caldwell
Thanks Ben, these look great!

On Tue, Jan 24, 2017 at 4:15 PM, Ben Greenman 
wrote:

> Hi Racket Users,
>
> I ordered a bunch of Racket stickers to celebrate the 6.8 release. Here's
> proof:
> http://www.ccs.neu.edu/home/types/resources/stickers.jpg
>
> If you send me your address, I will mail you some stickers. For free!*
>
> I'm thinking 4 stickers per request (2 rectangles, 2 circles), but if you
> live outside the US and promise to serve as a "volunteer regional sticker
> distributor" then I'll send more.**
>
> Peace, Love, and Racket,
> Ben
>
>
> * While supplies last. And if you want un-free stickers, you can make your
> own on stickermule.com or send a donation to RacketCon 2017.
>
> ** While supplies last, and subject to the internal dimensions of the
> cheapest padded envelope at my local US post office.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] Racket backwards compatible to schemer books?

2016-11-22 Thread Sam Caldwell
I think there are some minor incompatibilities. For example, the seasoned
schemer uses `letcc` whereas in racket you would write `let/cc`. I don't
know if these are catalogued somewhere.

- Sam Caldwell

On Fri, Nov 18, 2016 at 2:20 PM, Tim Johnson <tim042...@gmail.com> wrote:

> Hello racketeers :
>
> I retired as a coder. Now I can write in whatever programming
> language I wish to.
>
> I'd like to learn racket. I intend to start by working off of the
> Schemer books. I have the first three.
>
> Is racket fully compatible to the code in the schemer books?
> If not, is there a site that would detail any incompatibilities?
>
> Thanks
> --
> Tim
> http://www.akwebsoft.com, http://www.tj49.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] Re: Redex: macro expanding to a side-condition clause

2016-10-26 Thread Sam Caldwell
(cc'ing the list)

Cool, I hadn't seen that library. I think this approach would get the job
done.

Thanks,
Sam Caldwell

On Wed, Oct 26, 2016 at 12:25 PM, Sam Caldwell <s...@ccs.neu.edu> wrote:

> Cool, I hadn't seen that library. I think this approach would get the job
> done.
>
> Thanks,
> Sam Caldwell
>
> On Tue, Oct 25, 2016 at 10:33 AM, Dupéron Georges <
> jahvascriptman...@gmail.com> wrote:
>
>> Sam, would something like this work for you?
>>
>> I'm using the generic-syntax-expanders library to easily define expanders
>> (sorts of macros) which are expanded within uses of a wrapper of
>> define-judgment-form.
>>
>>
>>
>> #lang racket
>>
>> (require (rename-in redex
>> [define-judgment-form orig:define-judgment-form])
>>  generic-syntax-expanders)
>>
>> (define-language L
>>   (E number (+ E E)))
>>
>> (define-expander-type judgment-form)
>> (define-syntax (define-judgment-form stx)
>>   (syntax-case (expand-all-judgment-form-expanders stx) ()
>> [(self . rest)
>>  (with-syntax ([new-self (datum->syntax #'here
>> 'orig:define-judgment-form
>> #'self
>> #'self)])
>>(datum->syntax #'here
>>   `(,#'new-self . ,#'rest)
>>   stx
>>   stx))]))
>>
>> (define-judgment-form-expander where/not
>>   (λ (stx)
>> (syntax-case stx ()
>>   [(_ pat tm)
>>#'(side-condition ,(not (redex-match? L pat (term tm])))
>>
>> (define-judgment-form L
>>   #:mode (j I)
>>   [(where/not number E)
>>-
>>(j E)])
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Re: [racket-users] Redex: macro expanding to a side-condition clause

2016-10-24 Thread Sam Caldwell
Right, so I need a separate metafunction for each pattern I want to negate.

On Mon, Oct 24, 2016 at 6:56 PM, Robby Findler <ro...@eecs.northwestern.edu>
wrote:

> I am saying to write this:
>
> (define-metafunction L
>   [(not-thing pat) #false]
>   [(not-thing any) #true])
>
> and then where you wrote:
>
>   (where/not pat tm)
>
> write this:
>
>   (where #true (not-thing pat))
>
>
>
> On Mon, Oct 24, 2016 at 5:47 PM, Sam Caldwell <s...@ccs.neu.edu> wrote:
> >> In the meantime, consider using a metafunction with an `else` clause.
> >
> > This would entail fixing the pattern, right? As in, I can write a
> > metafunction deciding whether a term does not match a pattern, but I
> can't
> > write a metafunction taking both the term and the pattern.
> >
> > I'm ok with failed matches not being first-class in Redex, but I'm a
> little
> > disappointed if I can't create my own shorthand.
> >
> > Thanks,
> > Sam Caldwell
> >
> > On Mon, Oct 24, 2016 at 6:31 PM, Robby Findler <
> ro...@eecs.northwestern.edu>
> > wrote:
> >>
> >> Unfortunately, Redex's pattern language does not currently support
> >> `not`. It might be easy to add it, or maybe hard, or maybe impossible.
> >> Offhand, it seems probably possible to support in the unifier and
> >> impossible in the enumerator and not hard in the matcher.
> >>
> >> In the meantime, consider using a metafunction with an `else` clause.
> >>
> >> Robby
> >>
> >>
> >> On Mon, Oct 24, 2016 at 5:15 PM, Sam Caldwell <s...@ccs.neu.edu> wrote:
> >> > I have a Redex judgment that I would like to specify in terms of a
> >> > *failed*
> >> > pattern match. I can write this like so:
> >> >
> >> > [(side-condition ,(not (redex-match? L pat (term tm)))
> >> > --
> >> > ...]
> >> >
> >> > which works, but I would rather just abbreviate this using a macro
> >> > (since
> >> > afaict there are no existing constructs in redex to do this), so I
> could
> >> > write for instance:
> >> >
> >> > [(where/not pat tm)
> >> > --
> >> > ...]
> >> >
> >> > But then I get an error: "define-judgment-form: expected judgment form
> >> > name
> >> > in: where/not"
> >> >
> >> > Does anybody know how to achieve this?
> >> >
> >> > Thanks,
> >> > Sam Caldwell
> >> >
> >> > Full example:
> >> >
> >> > ==
> >> >
> >> > #lang racket
> >> >
> >> > (require redex)
> >> >
> >> > (define-language L
> >> >   (E number (+ E E)))
> >> >
> >> > (define-syntax (where/not stx)
> >> >   (syntax-case stx ()
> >> > [(_ pat tm)
> >> >  #'(side-condition ,(not (redex-match? L pat (term tm]))
> >> >
> >> > (define-judgment-form L
> >> >   #:mode (j I)
> >> >   [(where/not number E)
> >> >-
> >> >(j E)])
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "Racket Users" group.
> >> > To unsubscribe from this group and stop receiving emails from it, send
> >> > an
> >> > email to racket-users+unsubscr...@googlegroups.com.
> >> > For more options, visit https://groups.google.com/d/optout.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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] Redex: macro expanding to a side-condition clause

2016-10-24 Thread Sam Caldwell
> In the meantime, consider using a metafunction with an `else` clause.

This would entail fixing the pattern, right? As in, I can write a
metafunction deciding whether a term does not match a pattern, but I can't
write a metafunction taking both the term and the pattern.

I'm ok with failed matches not being first-class in Redex, but I'm a little
disappointed if I can't create my own shorthand.

Thanks,
Sam Caldwell

On Mon, Oct 24, 2016 at 6:31 PM, Robby Findler <ro...@eecs.northwestern.edu>
wrote:

> Unfortunately, Redex's pattern language does not currently support
> `not`. It might be easy to add it, or maybe hard, or maybe impossible.
> Offhand, it seems probably possible to support in the unifier and
> impossible in the enumerator and not hard in the matcher.
>
> In the meantime, consider using a metafunction with an `else` clause.
>
> Robby
>
>
> On Mon, Oct 24, 2016 at 5:15 PM, Sam Caldwell <s...@ccs.neu.edu> wrote:
> > I have a Redex judgment that I would like to specify in terms of a
> *failed*
> > pattern match. I can write this like so:
> >
> > [(side-condition ,(not (redex-match? L pat (term tm)))
> > --
> > ...]
> >
> > which works, but I would rather just abbreviate this using a macro (since
> > afaict there are no existing constructs in redex to do this), so I could
> > write for instance:
> >
> > [(where/not pat tm)
> > --
> > ...]
> >
> > But then I get an error: "define-judgment-form: expected judgment form
> name
> > in: where/not"
> >
> > Does anybody know how to achieve this?
> >
> > Thanks,
> > Sam Caldwell
> >
> > Full example:
> >
> > ==
> >
> > #lang racket
> >
> > (require redex)
> >
> > (define-language L
> >   (E number (+ E E)))
> >
> > (define-syntax (where/not stx)
> >   (syntax-case stx ()
> > [(_ pat tm)
> >  #'(side-condition ,(not (redex-match? L pat (term tm]))
> >
> > (define-judgment-form L
> >   #:mode (j I)
> >   [(where/not number E)
> >-
> >(j E)])
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>

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


[racket-users] Redex: macro expanding to a side-condition clause

2016-10-24 Thread Sam Caldwell
I have a Redex judgment that I would like to specify in terms of a *failed*
pattern match. I can write this like so:

[(side-condition ,(not (redex-match? L pat (term tm)))
--
...]

which works, but I would rather just abbreviate this using a macro (since
afaict there are no existing constructs in redex to do this), so I could
write for instance:

[(where/not pat tm)
--
...]

But then I get an error: "define-judgment-form: expected judgment form name
in: where/not"

Does anybody know how to achieve this?

Thanks,
Sam Caldwell

Full example:

==

#lang racket

(require redex)

(define-language L
  (E number (+ E E)))

(define-syntax (where/not stx)
  (syntax-case stx ()
[(_ pat tm)
 #'(side-condition ,(not (redex-match? L pat (term tm]))

(define-judgment-form L
  #:mode (j I)
  [(where/not number E)
   -
   (j E)])

-- 
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] Trouble with recursive lambda macros, using Y combinator

2016-09-11 Thread Sam Caldwell
I think the simplest solution to your problem would be to use the *full*
(for strict languages, I don't quite remember the name) Y-combinator rather
than just self-application, which is what you have right now. Then you can
just ditch `substitute-term` completely:

--
(define Y
  (lambda (f)
((lambda (g) (g g))
 (lambda (x) (f (lambda (y) ((x x) y)))

(define-syntax recursion
  (syntax-rules ()
[(_ label (args ...) body ...)
 (Y
  (lambda (label)
(lambda (args ...)
  body ...)))]))

--

> (define fact
(recursion fact (n)
(if (zero? n)
1
(* n (fact (sub1 n))
> (fact 0)
1
> (fact 10)
3628800

- Sam Caldwell

On Sun, Sep 11, 2016 at 9:15 AM, Jens Axel Søgaard <jensa...@soegaard.net>
wrote:

> Rather than use substitute-term you can bind name to do the right thing.
> For example:
>
> #lang racket
> (require (for-syntax syntax/parse))
>
> (define-syntax (recursion stx)
>   (syntax-parse stx
> [(_recursion name (arg ...) expr)
>  #'( (λ (x) (x x))
>  (λ (name)
>(λ (arg ...)
>  (let ([name (λ args (apply (name name) args))])
>expr]))
>
> ((recursion fact (n)
> (if (zero? n)
> 1
> (* n (fact (sub1 n)
>  5)
>
>
> 2016-09-11 5:54 GMT+02:00 Vasily Rybakov <madbada...@gmail.com>:
>
>> Hi!
>>
>> I'm learning Racket and I stumpbled into a couple of problems with macros.
>>
>> I tried to make macros that implements recursive lambda, but not the
>> classic one (that uses letre), but the one that uses Y combinator.
>>
>> So it should work like this:
>>
>> (recursion fact (n)
>> (if (zero? n)
>> 1
>> (* n (fact (sub1 n)
>>
>> transforms into
>>
>> ((lambda (x) (x x))
>> (lambda (fact)
>>   (lambda (n)
>>  (if (zero? n) 1 (* n ((fact fact) (sub1 n)))
>>
>> which produces recursive anonymous function to compute factorial.
>>
>> So I wrote this macros:
>>
>> (define-syntax recursion
>>   (syntax-rules ()
>> [(_ label (args ...) body ...)
>>  ((lambda (x) (x x))
>>   (lambda (label)
>> (lambda (args ...)
>>   (substitute-term label (label label) body) ...)))]))
>>
>> (substitute-term) macros is helper macros to substitute one piece of code
>> with another, here its fist version:
>>
>> (define-syntax (substitute-term stx)
>>   (syntax-case stx ()
>> [(_ term-from term-to body)
>>(cond
>>  [(null? (syntax-e #'body)) #'(void)]
>>  [(list? (syntax-e #'body)) #`#,(map (lambda (x) (append
>> (syntax-e #'(substitute-term term-from term-to)) (if (list? x) x (list
>> x (syntax-e #'body))]
>>  [else (if (equal? (syntax-e #'body) (syntax-e #'term-from))
>> #'term-to #'body)])]))
>>
>> >(substitute-term - + (- 1 2))
>> 3
>>
>> This works. But
>>
>> >(substitute-term and or (and #t #f))
>> or: bad syntax in: or
>>
>> Macro stepper shows that it expands into
>>
>> (or (substitute-term and or #t) (substitute-term and or #f))
>>
>> And after this step is "bad syntax" error. I couldn't figure why is this
>> and how to fix it. It raises "bad syntax" errors with all special forms for
>> some reason. Can somebody explain to me -- why? And how to fix it?
>>
>> Then I tried rewrite (substitute-term) macro:
>>
>> (define-syntax (substitute-term-2 stx)
>>   (syntax-case stx ()
>> [(substitute-term term-from term-to body)
>>  (datum->syntax stx (for-substitute-term (syntax->datum #'term-from)
>> (syntax->datum #'term-to) (syntax->datum #'body)))]))
>>
>> It uses helper function (define-for-syntax) which do all the work:
>>
>> (define-for-syntax (for-substitute-term term-from term-to expr)
>>   (cond
>> [(null? expr) (void)]
>> [(list? expr) (map (lambda (x) (apply for-substitute-term (list
>> term-from term-to x))) expr)]
>> [else (if (equal? expr term-from) term-to expr)]))
>>
>> >(substitute-term-2 and or (and #t #f))
>> #t
>>
>> Hurray! But if I use it in my (recursion) macro:
>>
>> (define-syntax recursion-2
>>   (syntax-rules ()
>> [(_ label (args ...) body ...)
>>  ((lambda (x) (x x))
>>   (lambda (label)
>> (lambda (args ...)
>>   (substitu

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

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

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

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

and then restricting your definitions of contexts:

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

or

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

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

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

- Sam Caldwell

On Tue, Sep 6, 2016 at 1:39 PM, Dupéron Georges <jahvascriptman...@gmail.com
> wrote:

> Hi all!
>
> I'm trying out redex, and I defined a simple language with (define v e)
> statements. I also defined an extended language, which allows expressions
> to be (lifted v' e'). A (lifted v' e') expression is replaced by v', and a
> definition (define v' e') is lifted to the top-level, just before the
> current statement.
>
> I tried to define a reduction from the simple+lifted language to the
> simple language. It makes the lifted definitions bubble up until they reach
> the top-level, and inserts them before their containing statement.
>
> Unfortunately, my reduction is ambiguous: when reducing the program
> (define result (+ (lifted x 1) (lifted y 2))), both lifted definitions can
> bubble up first and be inserted before the other. Therefore,
> apply-reduction-relation* returns two valid results:
>
> (begin (define x 1) (define y 2) (define result (+ x y)))
> (begin (define y 2) (define x 1) (define result (+ x y)))
>
> How can I avoid this problem?
>
> See the attached file or http://pasterack.org/pastes/44574 for the full
> code.
>
> Thanks!
> Georges Dupéron
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] Macro calling macro question

2016-05-20 Thread Sam Caldwell
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  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.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] What do you use macros for?

2016-04-08 Thread Sam Caldwell
I don't see how a lazy language would let me implement my own version of
`let`. Care to enlighten me?

- Sam Caldwell

On Fri, Apr 8, 2016 at 7:10 AM, Norman Gray <nor...@astro.gla.ac.uk> wrote:

>
> Greetings.
>
> Quoting Asumu quoting Matthias:
>
>  I'd like to propose that there are three disciplined uses of macros:
>>>
>>>  1. data sublanguages: I can write simple looking expressions and
>>> [...]
>>>
>>>  2. binding constructs: I can introduce new binding constructs with
>>> [...]
>>>
>>>  3. evaluation reordering: I can introduce constructs that delay/postpone
>>>  [...]
>>>[Note: In Haskell, you don't need that one.]
>>>
>>
> This is a seriously naive question, because I have only trivial experience
> with Haskell (and by extension other lazy languages), but aren't each of
> these things that you can do with a lazy language?
>
> If I can control when an expression is evaluated, then I can obviously do
> (3), but supposing I can also control the environment within which it's
> evaluated, can't I also do (2) and thence, with suitable juggling, go on to
> (1)?  Asumu's further example of 'use of macros that expand into submodules
> in order to provide metadata for other programs/tools' sounds at least
> complicated to do lazily, without macros, but not fundamentally impossible.
>
> Macros are obviously not the same as lazy evaluation (though from the
> point of view of the macro expander, perhaps all the post-compilation
> stages are 'lazy'), but I'm having a hard time seeing why it's obvious
> they're not isomorphic.
>
> I imagine there may be both pragmatic and fundamental semantic reasons why
> the two are different.
>
> All the best,
>
> Norman
>
>
> --
> Norman Gray  :  https://nxg.me.uk
> SUPA School of Physics and Astronomy, University of Glasgow, UK
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [racket-users] SEwPR PLT Redex code error? (pg 225)

2016-02-23 Thread Sam Caldwell
I am pretty sure it is a result of this change:

https://groups.google.com/d/topic/racket-users/blV3EEkJxVk/discussion

On Tue, Feb 23, 2016 at 1:23 PM, Matthias Felleisen 
wrote:

>
> This is must be a regression. The build-process for the second part
> includes running the figures (and their tests).
>
>
>
> On Feb 23, 2016, at 1:09 PM, Andrew Kent  wrote:
>
> > A student today pointed out the standard reduction definition for ISWIM
> on pg 225 in SEwPR is broken:
> >
> > #lang racket
> > (require redex)
> >
> > ;; iswim
> > ;; definition from pg 217
> > (define-language iswim
> >  ((M N L K) X (λ X M) (M M) b (o2 M M) (o1 M))
> >  (o o1 o2)
> >  (o1 add1 sub1 iszero)
> >  (o2 + - *)
> >  (b number)
> >  ((V U W) b X (λ X M))
> >  (E hole (V E) (E M) (o V ... E M ...))
> >  (X Y Z variable-not-otherwise-mentioned))
> >
> > (define-metafunction iswim
> >  subst : any ... -> any)
> >
> > ;; iswim-standard
> > ;; definition from pg 225
> > (define iswim-standard
> >  (reduction-relation
> >   iswim
> >   (v ((λ X M) V) (subst M X V) vω)
> >   (v (o b ...) (δ (o b ...)) δ)
> >   with
> >   [(--> (in-hole E M) (in-hole E N)) (v M N)]))
> >
> >
> > Error message: "reduction-relation: shortcut name may not be a
> non-terminal in: M"
> >
> > Only posting this here since I couldn't find anything about it on the
> errata.
> >
> > Have a good day!
> >
> > Best,
> > Andrew
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

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

2016-02-11 Thread Sam Caldwell
Yes, I mention seeing this in a bug report I filed last week:

https://github.com/racket/macro-debugger/issues/13

- Sam Caldwell

On Thu, Feb 11, 2016 at 11:37 AM, Scott Moore <sdmo...@fas.harvard.edu>
wrote:

> Yes, around 80% of the time if I disable macro hiding, and sometimes even
> with macro hiding if I’m moving back and forth through a long sequence of
> steps.
>
> I had been meaning to file a report...
>
> On February 11, 2016 at 11:27:21 AM, Matthias Felleisen (
> matth...@ccs.neu.edu) wrote:
>
>
> ... has anyone seen this error message from stepping thru macros:
>
> [:~/svn/2HtDP] matthias% sequence-contract-violation: negative: method
> set-max-width cannot be called, except in states (unlocked write-lock),
> args 834
> context...:
> /Users/matthias/plt/racket/collects/racket/private/more-scheme.rkt:148:2:
> call-with-break-parameterization
> /Users/matthias/plt/racket/share/pkgs/gui-lib/mred/private/lock.rkt:43:38
> /Users/matthias/plt/racket/collects/racket/private/more-scheme.rkt:265:2:
> call-with-exception-handler
> /Users/matthias/plt/racket/share/pkgs/gui-lib/mred/private/wxme/text.rkt:766:2:
> end-edit-sequence method in text%
> /Users/matthias/plt/racket/share/pkgs/macro-debugger/macro-debugger/view/stepper.rkt:438:4:
> update* method in macro-stepper-widget%
> /Users/matthias/plt/racket/share/pkgs/macro-debugger/macro-debugger/view/stepper.rkt:400:31
>
> .../more-scheme.rkt:261:28
> /Users/matthias/plt/racket/share/pkgs/macro-debugger/macro-debugger/view/stepper.rkt:369:24
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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] Redex - constraining what is used to fill a hole

2015-12-13 Thread Sam Caldwell
> I'm not completely following the design goals here because it seems
> like the desire to reduce only State-Qs could be achieved by writing
> rules that reduced only State-Qs (not arbitrary states). Or are you
> saying that State-Qs are only allowed in the context? If so, then you
> could write E differently?

I don't think I can constrain the rules to only operate on State-Qs
because the *outermost* State needs to reduce, and it does not need to
be a State-Q. I think this would lead to duplicating all of the
reduction rules; once for the outermost State and once for internal
State-Qs.

It's not clear to me how I would change the definition of E to achieve this.

> you could rewrite it using define-judgment-form

This seems fairly promising - looking at the docs I don't see any
reason define-judgment-form couldn't do what I want in a
straightforward manner.

Thanks for the help,
Sam Caldwell


On Sun, Dec 13, 2015 at 5:17 PM, Robby Findler <ro...@eecs.northwestern.edu>
wrote:

> I'm not completely following the design goals here because it seems
> like the desire to reduce only State-Qs could be achieved by writing
> rules that reduced only State-Qs (not arbitrary states). Or are you
> saying that State-Qs are only allowed in the context? If so, then you
> could write E differently? I think that all of this is expressible
> without using a feature like you want in Redex, but I'm not really
> getting precisely what you want so I'm hesitant to make more concrete
> suggestions.
>
> Regardless, if for some reason it is better to express your rewriting
> relation in the way that has actual premises, then you could rewrite
> it using define-judgment-form. Relations defined with
> define-judgment-form that have the mode (I O) or (O I) can be used
> with 'traces' and 'stepper' (as well as show-derivations).
>
> hth,
> Robby
>
>
> On Sat, Dec 12, 2015 at 8:21 PM, Sam Caldwell <s...@ccs.neu.edu> wrote:
> > Thanks for clarifying, Robby.
> >
> > I'm modeling reduction on nested states. In addition to a collection of
> > straightforward rules, there is a rule that specifies when to reduce a
> > state-inside-a-state. I can specify this using evaluation contexts, but
> in
> > order for the relation to remain deterministic I need to restrict which
> > nested-states are reduced to a particular subclass.
> >
> > I'm hoping this little model demonstrates what I'm trying to do:
> >
> > ==
> >
> > #lang racket
> >
> > (require redex)
> >
> > (define-language L
> >   (State (number
> >   (Event ...)  ;; "incoming" events
> >   (Event ...)  ;; "outgoing" events
> >   (State ...)))
> >   (Event string)
> >   ;; states with no outgoing events
> >   (State-Q (number
> > (Event ...)
> > ()
> > (State ...)))
> >   ;; states with no incoming or outgoing events
> >   (State-I (number
> > ()
> > ()
> > (State ...)))
> >   ;; Evaluation Contexts
> >   (E hole
> >  (number
> >   ()
> >   (Event ...)
> >   (State-I ... E State-Q ...
> >
> > (define red
> >   (reduction-relation
> >L
> >;; incoming events just increase a counter
> >(--> (number
> >  (Event_0 Event_n ...)
> >  (Event ...)
> >  (State ...))
> > (,(add1 (term number))
> >  (Event_n ...)
> >  (Event ...)
> >  (State ...))
> > handle)
> >;; once a State has processed all of its incoming Events, it can
> receive
> > an
> >;; outgoing Event from nested States.
> >(--> (number
> >  ()
> >  (Event_out ...)
> >  (State-Q ...
> >   (number_s
> >(Event_si ...)
> >(Event Event_so ...)
> >(State_s ...))
> >   State ...))
> > (number
> >  (Event Event_so ...)
> >  (Event_out ...)
> >  (State-Q ...
> >   (number_s
> >(Event_si ...)
> >()
> >(State_s ...))
> >   State ...))
> > receive)))
> >
> > #|
> > Want this to result in:
> > '((5 () () ((4 () () ()) (4 () () ()
> > |#
> > (apply-reduction-relation*
> >  red
> >  (term (0 ()
> >   ()
> >   ((1 ("hi" "hello" "ciao")
> > 

Re: [racket-users] Redex - constraining what is used to fill a hole

2015-12-12 Thread Sam Caldwell
Thanks for clarifying, Robby.

I'm modeling reduction on nested states. In addition to a collection of
straightforward rules, there is a rule that specifies when to reduce a
state-inside-a-state. I can specify this using evaluation contexts, but in
order for the relation to remain deterministic I need to restrict which
nested-states are reduced to a particular subclass.

I'm hoping this little model demonstrates what I'm trying to do:

==

#lang racket

(require redex)

(define-language L
  (State (number
  (Event ...)  ;; "incoming" events
  (Event ...)  ;; "outgoing" events
  (State ...)))
  (Event string)
  ;; states with no outgoing events
  (State-Q (number
(Event ...)
()
(State ...)))
  ;; states with no incoming or outgoing events
  (State-I (number
()
()
(State ...)))
  ;; Evaluation Contexts
  (E hole
 (number
  ()
  (Event ...)
  (State-I ... E State-Q ...

(define red
  (reduction-relation
   L
   ;; incoming events just increase a counter
   (--> (number
 (Event_0 Event_n ...)
 (Event ...)
 (State ...))
(,(add1 (term number))
 (Event_n ...)
 (Event ...)
 (State ...))
handle)
   ;; once a State has processed all of its incoming Events, it can receive
an
   ;; outgoing Event from nested States.
   (--> (number
 ()
 (Event_out ...)
 (State-Q ...
  (number_s
   (Event_si ...)
   (Event Event_so ...)
   (State_s ...))
  State ...))
(number
 (Event Event_so ...)
 (Event_out ...)
 (State-Q ...
  (number_s
   (Event_si ...)
   ()
   (State_s ...))
  State ...))
receive)))

#|
Want this to result in:
'((5 () () ((4 () () ()) (4 () () ()
|#
(apply-reduction-relation*
 red
 (term (0 ()
  ()
  ((1 ("hi" "hello" "ciao")
  ("zip" "zap" "zooey")
  ())
   (2 ("where" "fore")
  ("art" "thou")
  ())

==

That model allows the top-most State to process incoming Events and receive
Events from its direct children. But, I also want child States to reduce
using
the same rules. To keep my relation deterministic, I only want to step child
States that are also State-Q's. This is how I ended up trying to add a
shortcut like:

[(--> (in-hole E State-Q) (in-hole E State))
 (==> State-Q State)]

I was able to get the behavior I want by calling apply-reduction-relation
from
inside a rule:

(--> (in-hole E State-Q)
 (in-hole E State)
 (side-condition (not (redex-match? L hole (term E
 (where (State) ,(apply-reduction-relation red (term State-Q

But I can't say I felt great about doing so. (The side-condition is needed
to
prevent infinite looping). Is there a cleaner way to achieve the same
result?

Thanks,
Sam Caldwell


On Sat, Dec 12, 2015 at 11:11 AM, Robby Findler <ro...@eecs.northwestern.edu
> wrote:

> I can see why you might have expected that to work that way.
> Unfortunately, it doesn't. The identifiers in those places in
> shortcuts (Add2, x, and n in your examples below) are not pattern
> positions. They are simply identifiers.
>
> In the code you wrote, one could change the rule's left-hand side to
> (+ V_1 V_2) to achieve the desired effect, but maybe that doesn't work
> in your larger model? Perhaps if you explained a little more why
> something like that is problematic, we could be of more use.
>
> Meanwhile, I've pushed a fix to the bug in the error-checking that you
> found, added some more checking, and tried to emphasize this point
> more clearly in the documentation. The commit cbb2d88b would probably
> have been the most helpful to you, but it's backwards incompatible, so
> it may need to be reverted.
>
> Robby
>
> On Fri, Dec 11, 2015 at 3:09 PM, Sam Caldwell <s...@ccs.neu.edu> wrote:
> > Hi,
> >
> > I'm working on a redex model where I want to constrain the shape of terms
> > used
> > to fill the hole in an evaluation context. I thought it would be fairly
> > straightforward to do so using a `with` clause in my reduction-relation,
> but
> > I've run into some difficulty, and consulting the docs [1] left me
> unsure of
> > where I went wrong.
> >
> > In the docs for `reduction-relation`, the old-arrow-name clause of
> shortcuts
> > are defined in terms of patterns and terms. However, the docs later say
> "The
> > left- and right-hand sides of a shortcut definition ar

[racket-users] Redex - constraining what is used to fill a hole

2015-12-11 Thread Sam Caldwell
Hi,

I'm working on a redex model where I want to constrain the shape of terms
used
to fill the hole in an evaluation context. I thought it would be fairly
straightforward to do so using a `with` clause in my reduction-relation, but
I've run into some difficulty, and consulting the docs [1] left me unsure of
where I went wrong.

In the docs for `reduction-relation`, the old-arrow-name clause of shortcuts
are defined in terms of patterns and terms. However, the docs later say "The
left- and right-hand sides of a shortcut definition are identifiers, not
patterns and terms." I don't understand what is and is not allowed when
using
shortcuts.

I have a small model that I think illustrates what I'm after. Say I have a
tiny addition language but for some reason I want to restrict reduction to
two-argument terms:

==

#lang racket

(require redex)

(define-language add
  (M (+ M ...) V)
  (V natural)
  (Add2 (+ V V))
  (E hole (+ V ... hole M ...)))

(define red
  (reduction-relation
   add
   (==> (+ V ...)
,(apply + (term (V ...)))
+)
   with
   [(--> (in-hole E Add2) (in-hole E n))
(==> Add2 n)]))

==

This does not behave as I would have expected, for example reducing
`(term (+ 1 2 (+ 3 4) 4 (+ 0 1)))` down to `15`.

It seems like the issue is that `Add2` in the shortcut is not being used as
a
pattern. For example, if I replace `Add2` with its definition:

[(--> (in-hole E (name x (+ V V))) (in-hole E n))
(==> x n)]

I get the following error message:

free-identifier=?: contract violation
  expected: identifier?
  given: #
  argument position: 2nd
  other arguments.:

So my question boils down to:
1) What is/is not allowed in each position when defining a shortcut?
2) How can I constrain what is used to fill a hole, as attempted in my
example?

Thanks,
Sam Caldwell

[1]
http://docs.racket-lang.org/redex/The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._reduction-relation%29%29

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