Re: [racket-users] Typed Racket Type Annotations - Best Practices?

2017-06-29 Thread 'John Clements' via Racket Users

> On Jun 29, 2017, at 17:33, Zelphir Kaltstahl  
> wrote:
> 
> A while ago I started looking at Typed Racket and today I took a look again.
> 
> The documentation says:
> 
>> Typed Racket provides modified versions of core Racket forms, which permit 
>> type annotations. Previous versions of Typed Racket provided these with a : 
>> suffix, but these are now only included as legacy forms for backwards 
>> compatibility.
> 
> To me this sounds as if I am not supposed to use them anymore. So I tried the 
> following, which works:
> 
> ~~~
> racket -I typed/racket
> 
> (let ([x 7.0])
>  (ann x Positive-Flonum)
>  x)
> ~~~
> 
> So I could use `ann` instead, but is it not as short as the colon notation.
> Then I also discovered:
> 
> ~~~
> (let ([x 7.0])
>  (: x Positive-Flonum)
>  x)
> ~~~
> 
> Which also works. It is not a change in a core form, so I guess this is not 
> part of the stuff kept for backward compatibility (?).
> 
> I'd like to know what the best practice of writing type annotations is. The 
> guide in the documentation still uses a lot of the changed core forms, which 
> is my impression are not recommended, since they're only kept for backwards 
> compatibility, so one should not rely on them.

I believe this text is referring to forms such as for: and lambda: — that is, 
syntactic terms where the lambda is attached to the identifier. I believe this 
text is *not* referring to the use of the colon as a simple “has-type” form.

John



-- 
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] Custom reader that's a strict subset of racket

2017-06-29 Thread Sam Waxman
On Thursday, June 29, 2017 at 11:17:12 PM UTC-4, Philip McGrath wrote:
> I think you might be able to leave the reader as-is and just re-define 
> #%datum to reject whatever kinds of literal data you don't want to allow.
> 
> 
> 
> -Philip
> 
> 
> 
> On Thu, Jun 29, 2017 at 9:44 PM, Sam Waxman  wrote:
> Hello,
> 
> 
> 
> I'm building a #lang, and I don't want it to have a few things like complex 
> numbers, or vectors. Other than the things I don't want, the reader would be 
> identical to racket's. Is there an easy way to "turn off" the things I don't 
> want, so to speak, and take Racket's reader and delete the things I don't 
> need? The alternative, of course, would be to write my own reader from 
> scratch. Just seems a bit silly when there's a perfectly good one already 
> written that has everything I need.
> 
> 
> 
> 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...@googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

Shockingly simple and very clever. That'll do it! Many thanks.

-- 
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] Custom reader that's a strict subset of racket

2017-06-29 Thread Philip McGrath
I think you might be able to leave the reader as-is and just re-define
#%datum to reject whatever kinds of literal data you don't want to allow.

-Philip

On Thu, Jun 29, 2017 at 9:44 PM, Sam Waxman  wrote:

> Hello,
>
> I'm building a #lang, and I don't want it to have a few things like
> complex numbers, or vectors. Other than the things I don't want, the reader
> would be identical to racket's. Is there an easy way to "turn off" the
> things I don't want, so to speak, and take Racket's reader and delete the
> things I don't need? The alternative, of course, would be to write my own
> reader from scratch. Just seems a bit silly when there's a perfectly good
> one already written that has everything I need.
>
> 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] Missing request-post-data/raw (from web-server/http)

2017-06-29 Thread Philip McGrath
Thanks for your comments.

The only legal files to upload in this case are plain text, so I'm not too
worried about size. I'm relying on the web-server libraries to deal with
any malicious attempts to send overwhelmingly large files (if that's a bad
idea, I'd definitely appreciate hearing it!). Other parts of the
application are implemented in #lang web-server, including some access
control logic surrounding the requests that are proxied to the external
service.

With other requests, the  post-data/raw field of the request struct has
been #f only when the method field is #"GET": with POST requests, it has
otherwise (and I thought it always would) contained the raw POST data e.g. #
"corpus=austen=corpus.CorpusMetadata". I thought the bindings from
the bindings/raw-promise field were simply an abstraction over the
post-data/raw (and/or query part of the uri field), which is why I'm
confused that this POST request has bindings, but has #f for its
post-data/raw.

-Philip

On Thu, Jun 29, 2017 at 9:44 PM, Neil Van Dyke  wrote:

> I don't know the answer to your particular questions with `web-server`
> (I've made my own implementations of this in the past), and these comments
> might not apply to your particular application, but I'll mention here for
> whomever is interested...
>
> It sounds like you're using this, which might preempt your question:
>
> post-data/raw : (or/c false/c bytes?)
>>
>
> Does your application permit a large file upload (an uploaded DVD-ROM
> ".iso" file, like for a Linux distro install disc 1, is typically a few
> gigabytes, and video files can also get huge), and is your program
> (including libraries it uses) going to try to allocate gigabytes at a time
> just for one HTTP request?
>
> If the `POST` data is potentially huge, you might want to think about
> doing stream reading of it (i.e., not sucking it all into memory before you
> do something with it), and sending blocks out your proxy approximately as
> soon as they come in (without buffering too much).  That can make your
> program more robust, lower latency, and maybe even improve overall speed.
>
> Or, if you want to keep getting a convenient byte string out of the MIME
> parser, and you plan to reject huge `POST` data before it
> accidentally/intentionally DoS's your server, that will probably happen
> either as the HTTP request is being read, or in the MIME multipart parser
> (when the request is in MIME multipart, which `POST` isn't always, and if
> the HTTP code hands off a pretty raw input port to multipart parsing code,
> which it should).  This is because you can't assume that HTTP or part
> headers will tell you the content size before you read the content --
> sometimes you have to read to find the EOF or the MIME boundary string
> kludge.
>
> I think streaming algorithms are usually the way to go for potentially
> huge data.  (Well, until you then get into what I'll call "poetic license"
> situations, in which you know how to do it in streaming, and you know why
> you don't have to stream in this case.)
>
> --
> 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] Missing request-post-data/raw (from web-server/http)

2017-06-29 Thread Neil Van Dyke
I don't know the answer to your particular questions with `web-server` 
(I've made my own implementations of this in the past), and these 
comments might not apply to your particular application, but I'll 
mention here for whomever is interested...


It sounds like you're using this, which might preempt your question:


post-data/raw : (or/c false/c bytes?)


Does your application permit a large file upload (an uploaded DVD-ROM 
".iso" file, like for a Linux distro install disc 1, is typically a few 
gigabytes, and video files can also get huge), and is your program 
(including libraries it uses) going to try to allocate gigabytes at a 
time just for one HTTP request?


If the `POST` data is potentially huge, you might want to think about 
doing stream reading of it (i.e., not sucking it all into memory before 
you do something with it), and sending blocks out your proxy 
approximately as soon as they come in (without buffering too much).  
That can make your program more robust, lower latency, and maybe even 
improve overall speed.


Or, if you want to keep getting a convenient byte string out of the MIME 
parser, and you plan to reject huge `POST` data before it 
accidentally/intentionally DoS's your server, that will probably happen 
either as the HTTP request is being read, or in the MIME multipart 
parser (when the request is in MIME multipart, which `POST` isn't 
always, and if the HTTP code hands off a pretty raw input port to 
multipart parsing code, which it should).  This is because you can't 
assume that HTTP or part headers will tell you the content size before 
you read the content -- sometimes you have to read to find the EOF or 
the MIME boundary string kludge.


I think streaming algorithms are usually the way to go for potentially 
huge data.  (Well, until you then get into what I'll call "poetic 
license" situations, in which you know how to do it in streaming, and 
you know why you don't have to stream in this case.)


--
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] Missing request-post-data/raw (from web-server/http)

2017-06-29 Thread Philip McGrath
I'm working on a Racket web application for which I need to proxy certain
requests to a non-Racket service over HTTP. I've built a very basic proxy
on top of http-sendrecv/url that works quite well for the most part.

For POST requests, I pass the request-post-data/raw of the original request
as the #:data argument of http-sendrecv/url.

However, I've discovered that certain POST requests (specifically involving
file uploads) are not working as expected. On these requests, Chrome
reports that it is performing a request with a header
Content-Type:multipart/form-data;
boundary=WebKitFormBoundaryAJOgATwBujJhhtbY and a payload as follows:

--WebKitFormBoundaryAJOgATwBujJhhtbY
Content-Disposition: form-data; name="tool"
corpus.CorpusCreator
--WebKitFormBoundaryAJOgATwBujJhhtbY
Content-Disposition: form-data; name="palette"
default
--WebKitFormBoundaryAJOgATwBujJhhtbY
Content-Disposition: form-data; name="textarea-1014-inputEl"
Type in one or more URLs on separate lines or paste in a full text.
--WebKitFormBoundaryAJOgATwBujJhhtbY
Content-Disposition: form-data; name="upload"; filename="tmp-file.txt"
Content-Type: text/plain
--WebKitFormBoundaryAJOgATwBujJhhtbY--


However, at the Racket level, request-post-data/raw returns #f for these
requests — but, adding to my confusion, the bindings still show up
in request-bindings/raw.

Why doesn't this content show up in request-post-data/raw? Is there a way
to access the raw, original data for these requests, or do I need to
somehow reconstruct it from the bindings?

Thanks very much,
Philip

-- 
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] Typed Racket Type Annotations - Best Practices?

2017-06-29 Thread Zelphir Kaltstahl
A while ago I started looking at Typed Racket and today I took a look again.

The documentation says:

> Typed Racket provides modified versions of core Racket forms, which permit 
> type annotations. Previous versions of Typed Racket provided these with a : 
> suffix, but these are now only included as legacy forms for backwards 
> compatibility.

To me this sounds as if I am not supposed to use them anymore. So I tried the 
following, which works:

~~~
racket -I typed/racket

(let ([x 7.0])
  (ann x Positive-Flonum)
  x)
~~~

So I could use `ann` instead, but is it not as short as the colon notation.
Then I also discovered:

~~~
(let ([x 7.0])
  (: x Positive-Flonum)
  x)
~~~

Which also works. It is not a change in a core form, so I guess this is not 
part of the stuff kept for backward compatibility (?).

I'd like to know what the best practice of writing type annotations is. The 
guide in the documentation still uses a lot of the changed core forms, which is 
my impression are not recommended, since they're only kept for backwards 
compatibility, so one should not rely on 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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Testing #langs

2017-06-29 Thread 'John Clements' via users-redirect

> On Jun 29, 2017, at 09:08, Sam Waxman  wrote:
> 
> On Thursday, June 29, 2017 at 11:49:49 AM UTC-4, 'John Clements' via 
> users-redirect wrote:
>> Oops forgot to cc: list
>> 
>>> On Jun 29, 2017, at 08:49, John Clements  wrote:
>>> 
 
 On Jun 29, 2017, at 08:30, Sam Waxman  wrote:
 
 Hey all,
 
 I've been running into a lot of major roadblocks when it comes to writing 
 good tests for some #langs that I've made, for a number of reasons.
 
 Ideally, I want a function called
 (check-eq-program? "program1" "program2")
 That will run each program in a fresh module of my #lang, check what gets 
 printed out, and compare them for equality.
 
 I'm not quite sure how to write a function that creates and runs code in a 
 fresh module though.
 
 The fresh module is necessary for a number of reasons: If all of the 
 programs worked in the same module, they would occasionally interfere with 
 each other, as the #%module-begin's some of my #langs have initialize some 
 "global variables" that need to be fresh/reinitialized every time a new 
 program runs.
 
 Some languages also work with continuations, and if they all ran in one 
 module, would alter control flow so that only one program could ever run 
 (they have aborts in odd places).
 
 Ideally, the tests could be run in #lang racket instead of my own 
 languages, so that the tests wouldn't be part of my language, so it 
 probably makes sense that check-eq-program would have to take in a third 
 argument for the language to use
 
 (check-eq-program prog1 prog2 lang) Rackunit sadly does not seem to have 
 anything good for these kinds of tests.
 
 Can anyone offer some guidance on how to write a function like this, or if 
 there's an easier way to go about this?
>>> 
>>> I think this may be a great deal easier than you think… or maybe impossible.
>>> 
>>> Specifically: the basic idea behind racket’s #lang mechanism is that a 
>>> program is known to be in a particular language when it’s written. For this 
>>> reason, your `check-eq-program` form doesn’t make sense, because the 
>>> programs you’re testing will already be written in a fixed language.
>>> 
>>> I’m a bit confused by your terminology when you say “if all of the programs 
>>> worked in the same module"; specifically, a #lang declaration expands into 
>>> a module, so it’s more or less impossible to write a function in a 
>>> different #lang that isn’t in its own module.
>>> 
>>> The easy case: if your two programs are written as modules, and each one 
>>> has an entry point—a (main) function, perhaps—it sounds like it would be 
>>> sufficient simply to parameterize (current-output-port) to capture the 
>>> output and then call the corresponding function. If not, then you could 
>>> potentially use some combination of (make-namespace-anchor) and (eval)… but 
>>> my humble opinion is that in this case … it would be easier simply to 
>>> create a (main) function as a wrapper. 
>>> 
>>> Apologies if what I’m saying doesn’t make sense; I would also encourage you 
>>> to create a small example, to clarify what you’re asking. 
>>> 
>>> John
> 
> Hey, thanks for the response. To clear up what I'm saying a bit,
> 
> Let's say that one of my languages has a global variable called 
> "NumberFuncsDefined", and every time I define a function in my language, it 
> increments by one. I want to check if the two programs
> 
> "(define (f) 1)
> NumberFuncsDefined"
> 
> and
> "(define (g) 2)
> NumberFuncsDefined"
> 
> result in the same thing, so I write
> 
> (check-eq-program 
>[(define (f) 1) NumberFuncsDefined)]
>[(define (g) 2) NumberFuncsDefined)])
> 
> I want this to return true, because both programs defined one function, so 
> both programs should return 1 in my language. If they're working in the same 
> module though (instead of two fresh copies of the module), the first program 
> will increment NumberFuncsDefined, then the second program will be in the 
> same module with the same NumberFuncsDefined, it'll increment it, and now 
> NumberFuncsDefined will be 2 instead of one.


Okay, I think I’m getting the picture now. You want to test that your #lang 
works correctly. 

Here’s some code that will help get you into trouble:

#lang racket

(define-namespace-anchor my-ns-anchor)

(define (run-in-mylang module-str binding)
  (parameterize ([read-accept-lang #t]
 [read-accept-reader #t]
 [current-namespace (namespace-anchor->namespace
 my-ns-anchor)])
(eval
 (call-with-input-string
 module-str
 (λ (p) (read-syntax 'zz p
(dynamic-require ''anonymous-module 'f)))

(run-in-mylang "#lang racket
(provide (all-defined-out))
(define f 13)" 'f)

For your tests, of course, the #lang racket would be a different 

Re: [racket-users] Is there a way to check whether syntax is an expression or a define statement?

2017-06-29 Thread Matthew Flatt
At Thu, 29 Jun 2017 09:32:24 -0700 (PDT), Sam Waxman wrote:
> "The only way to check whether a form is an expression or definition is
> to partially expand it and match on the form." 
> - This seems sort of rough to believe. If you shadow the syntax-rule for 
> define so that (define id binding) always just returns the number 1, then (+ 
> (define a 1) 1) will work perfectly, so somehow racket knows that the first 
> define is not an expression, whereas the second is. If you partially expand 
> it 
> and look at it's form, doesn't that just tell you that it expands into 
> something called define? Can't you not figure out if that's racket's define 
> or 
> a user-defined, expression define?

By "partial expansion", I meant expansion of the immediate form to a
core form as in

http://docs.racket-lang.org/reference/syntax-model.html?q=partial%20expansion#%28tech._partial._expansion%29

and as implemented by `local-expand` with a non-empty stop list.

So, in your example, the expansion of `(define a 1)` won't stop there,
since `define` doesn't have a core binding --- and if you make the
example `define-values` instead of `define` as a macro that expands to
`1`, that `define-values` still won't be bound to the core form.


> "In this case, maybe you want to report the error from the
> implementation `func` by using `syntax-local-context` to detect when
> it's being used in an expression position."
> 
> I just tried this and it worked pretty nicely! Thanks! Do you know if there's 
> any way to adapt this to let statements? I.e.
> 
> (my-let () (func a(x) x))
> 
> Syntax-local-context just tells me that the func is in an internal-definition 
> position, but I'd like a way of saying "If the LAST body of the let is an 
> internal-definition, do something, and if not, do something else."

No, there's not currently a way for a macro to know that expansion is
in the last position with an internal-definition sequence.

-- 
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] Hint on opening enclosing directory of current file from DrRacket

2017-06-29 Thread Tim Hanson
Heh, cool, Laurent! This dabbler had missed this until now -- I will read and 
probably use.

Cheers, tim

-- 
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] Is there a way to check whether syntax is an expression or a define statement?

2017-06-29 Thread Sam Waxman
On Thursday, June 29, 2017 at 11:47:00 AM UTC-4, Matthew Flatt wrote:
> At Thu, 29 Jun 2017 08:10:25 -0700 (PDT), Sam Waxman wrote:
> > One of my constructs, (func name(args) body), defines a function that's 
> > able 
> > to be called afterwards, and it desugars into a pretty regular define 
> > statement. [...]
> > 
> > While I don't want this to be allowed, I'd like to catch this and
> > throw my own errors if this happens. The only way I can really
> > imagine doing this is to modify all the functions I have that take in
> > expressions (+ - * / let ...) and give them contracts that say "Hey,
> > check to make sure your arguments are expressions, and if not, throw
> > this syntax error!"
> 
> The only way to check whether a form is an expression or definition is
> to partially expand it and match on the form.
> 
> In this case, maybe you want to report the error from the
> implementation `func` by using `syntax-local-context` to detect when
> it's being used in an expression position.

"The only way to check whether a form is an expression or definition is
to partially expand it and match on the form." 
- This seems sort of rough to believe. If you shadow the syntax-rule for define 
so that (define id binding) always just returns the number 1, then (+ (define a 
1) 1) will work perfectly, so somehow racket knows that the first define is not 
an expression, whereas the second is. If you partially expand it and look at 
it's form, doesn't that just tell you that it expands into something called 
define? Can't you not figure out if that's racket's define or a user-defined, 
expression define?

"In this case, maybe you want to report the error from the
implementation `func` by using `syntax-local-context` to detect when
it's being used in an expression position."

I just tried this and it worked pretty nicely! Thanks! Do you know if there's 
any way to adapt this to let statements? I.e.

(my-let () (func a(x) x))

Syntax-local-context just tells me that the func is in an internal-definition 
position, but I'd like a way of saying "If the LAST body of the let is an 
internal-definition, do something, and if not, do something else."

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


Re: [racket-users] Testing #langs

2017-06-29 Thread Sam Waxman
On Thursday, June 29, 2017 at 11:49:49 AM UTC-4, 'John Clements' via 
users-redirect wrote:
> Oops forgot to cc: list
> 
> > On Jun 29, 2017, at 08:49, John Clements  wrote:
> > 
> >> 
> >> On Jun 29, 2017, at 08:30, Sam Waxman  wrote:
> >> 
> >> Hey all,
> >> 
> >> I've been running into a lot of major roadblocks when it comes to writing 
> >> good tests for some #langs that I've made, for a number of reasons.
> >> 
> >> Ideally, I want a function called
> >> (check-eq-program? "program1" "program2")
> >> That will run each program in a fresh module of my #lang, check what gets 
> >> printed out, and compare them for equality.
> >> 
> >> I'm not quite sure how to write a function that creates and runs code in a 
> >> fresh module though.
> >> 
> >> The fresh module is necessary for a number of reasons: If all of the 
> >> programs worked in the same module, they would occasionally interfere with 
> >> each other, as the #%module-begin's some of my #langs have initialize some 
> >> "global variables" that need to be fresh/reinitialized every time a new 
> >> program runs.
> >> 
> >> Some languages also work with continuations, and if they all ran in one 
> >> module, would alter control flow so that only one program could ever run 
> >> (they have aborts in odd places).
> >> 
> >> Ideally, the tests could be run in #lang racket instead of my own 
> >> languages, so that the tests wouldn't be part of my language, so it 
> >> probably makes sense that check-eq-program would have to take in a third 
> >> argument for the language to use
> >> 
> >> (check-eq-program prog1 prog2 lang) Rackunit sadly does not seem to have 
> >> anything good for these kinds of tests.
> >> 
> >> Can anyone offer some guidance on how to write a function like this, or if 
> >> there's an easier way to go about this?
> > 
> > I think this may be a great deal easier than you think… or maybe impossible.
> > 
> > Specifically: the basic idea behind racket’s #lang mechanism is that a 
> > program is known to be in a particular language when it’s written. For this 
> > reason, your `check-eq-program` form doesn’t make sense, because the 
> > programs you’re testing will already be written in a fixed language.
> > 
> > I’m a bit confused by your terminology when you say “if all of the programs 
> > worked in the same module"; specifically, a #lang declaration expands into 
> > a module, so it’s more or less impossible to write a function in a 
> > different #lang that isn’t in its own module.
> > 
> > The easy case: if your two programs are written as modules, and each one 
> > has an entry point—a (main) function, perhaps—it sounds like it would be 
> > sufficient simply to parameterize (current-output-port) to capture the 
> > output and then call the corresponding function. If not, then you could 
> > potentially use some combination of (make-namespace-anchor) and (eval)… but 
> > my humble opinion is that in this case … it would be easier simply to 
> > create a (main) function as a wrapper. 
> > 
> > Apologies if what I’m saying doesn’t make sense; I would also encourage you 
> > to create a small example, to clarify what you’re asking. 
> > 
> > John

Hey, thanks for the response. To clear up what I'm saying a bit,

Let's say that one of my languages has a global variable called 
"NumberFuncsDefined", and every time I define a function in my language, it 
increments by one. I want to check if the two programs

"(define (f) 1)
NumberFuncsDefined"

and
"(define (g) 2)
NumberFuncsDefined"

result in the same thing, so I write

(check-eq-program 
[(define (f) 1) NumberFuncsDefined)]
[(define (g) 2) NumberFuncsDefined)])

I want this to return true, because both programs defined one function, so both 
programs should return 1 in my language. If they're working in the same module 
though (instead of two fresh copies of the module), the first program will 
increment NumberFuncsDefined, then the second program will be in the same 
module with the same NumberFuncsDefined, it'll increment it, and now 
NumberFuncsDefined will be 2 instead of one.

-- 
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] Re: Checking if two lists contain a word

2017-06-29 Thread philipp . thiess1999
Am Sonntag, 25. Juni 2017 19:40:08 UTC+2 schrieb philipp.t...@gmail.com:
> Hello its me again,
> 
> I have the task to make a funcition who checks if two lists contain a word.
> 
> I made a function which does that with one lst but I dont find a way to do it 
> with two lists. There must be some easy trick but I dont find it.
> 
> The function has to look like this: (test2 word list1 list2) and its only 
> allowed to use one function.
> 
> Here is my function for checking one list. Can someone edit it so I can make 
> it with two lists? Would help me alot.
> 
> 
> 
> 
> #lang racket
> 
> 
> (define (test1 word book)
> 
>   (cond ((null? book) '(false))
> 
> ((equal? word (first book)) '(true))
> 
> (else (test1 word (rest book)

Thanks for the advice. I have no more question! :)

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


Re: [racket-users] Testing #langs

2017-06-29 Thread 'John Clements' via users-redirect
Oops forgot to cc: list

> On Jun 29, 2017, at 08:49, John Clements  wrote:
> 
>> 
>> On Jun 29, 2017, at 08:30, Sam Waxman  wrote:
>> 
>> Hey all,
>> 
>> I've been running into a lot of major roadblocks when it comes to writing 
>> good tests for some #langs that I've made, for a number of reasons.
>> 
>> Ideally, I want a function called
>> (check-eq-program? "program1" "program2")
>> That will run each program in a fresh module of my #lang, check what gets 
>> printed out, and compare them for equality.
>> 
>> I'm not quite sure how to write a function that creates and runs code in a 
>> fresh module though.
>> 
>> The fresh module is necessary for a number of reasons: If all of the 
>> programs worked in the same module, they would occasionally interfere with 
>> each other, as the #%module-begin's some of my #langs have initialize some 
>> "global variables" that need to be fresh/reinitialized every time a new 
>> program runs.
>> 
>> Some languages also work with continuations, and if they all ran in one 
>> module, would alter control flow so that only one program could ever run 
>> (they have aborts in odd places).
>> 
>> Ideally, the tests could be run in #lang racket instead of my own languages, 
>> so that the tests wouldn't be part of my language, so it probably makes 
>> sense that check-eq-program would have to take in a third argument for the 
>> language to use
>> 
>> (check-eq-program prog1 prog2 lang) Rackunit sadly does not seem to have 
>> anything good for these kinds of tests.
>> 
>> Can anyone offer some guidance on how to write a function like this, or if 
>> there's an easier way to go about this?
> 
> I think this may be a great deal easier than you think… or maybe impossible.
> 
> Specifically: the basic idea behind racket’s #lang mechanism is that a 
> program is known to be in a particular language when it’s written. For this 
> reason, your `check-eq-program` form doesn’t make sense, because the programs 
> you’re testing will already be written in a fixed language.
> 
> I’m a bit confused by your terminology when you say “if all of the programs 
> worked in the same module"; specifically, a #lang declaration expands into a 
> module, so it’s more or less impossible to write a function in a different 
> #lang that isn’t in its own module.
> 
> The easy case: if your two programs are written as modules, and each one has 
> an entry point—a (main) function, perhaps—it sounds like it would be 
> sufficient simply to parameterize (current-output-port) to capture the output 
> and then call the corresponding function. If not, then you could potentially 
> use some combination of (make-namespace-anchor) and (eval)… but my humble 
> opinion is that in this case … it would be easier simply to create a (main) 
> function as a wrapper. 
> 
> Apologies if what I’m saying doesn’t make sense; I would also encourage you 
> to create a small example, to clarify what you’re asking. 
> 
> John



-- 
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] on the name of a data structure

2017-06-29 Thread David Storrs
Looks sort of like a quaternary tree to me.  It's the same definition as
your BinaryTree except that there are four branches on each level.  They
are in substructures, so maybe it's indirect-quaternary-tree?

As an aside, instead of CamelCase and UPPERCASE, Racket typically names
things in all lower case with hyphen separators.





On Wed, Jun 28, 2017 at 7:59 AM, Daniel Bastos  wrote:

> To me a binary tree can be defined like this.
>
> ;; A BinaryTree is either
> ;;   - false OR
> ;;   - (BinaryTree Anything BinaryTree BinaryTree)
>
> I built a data structure which looked like a tree, but I think it's
> different.  What should this be called?  I called it a blob since I didn't
> know what it was.
>
> ;; A Blob is either
> ;;   - false OR
> ;;   - (Blob Stuff Stuff)
>
> ;; A Stuff is either
> ;;   - false OR
> ;;   - (Stuff Anything Blob Blob)
>
> It looks like a BinaryTree.  Inside a blob there are two objects of type
> Stuff each of which points to two other Blobs.  (Much like a binary tree
> with left and right branches pointing each to two other binary trees.)
>
> (*) Examples of blobs
>
> 1. FALSE
>
> 2. (BLOB (STUFF 'left FALSE) (STUFF 'right FALSE))
>
> 3. (BLOB
>(STUFF 'left (BLOB (STUFF 'x FALSE) (STUFF 'y FALSE)))
>(STUFF 'rigt (BLOB (STUFF 'a FALSE) (STUFF 'b FALSE
>
> Thank you!
>
> --
> 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] Is there a way to check whether syntax is an expression or a define statement?

2017-06-29 Thread Matthew Flatt
At Thu, 29 Jun 2017 08:10:25 -0700 (PDT), Sam Waxman wrote:
> One of my constructs, (func name(args) body), defines a function that's able 
> to be called afterwards, and it desugars into a pretty regular define 
> statement. [...]
> 
> While I don't want this to be allowed, I'd like to catch this and
> throw my own errors if this happens. The only way I can really
> imagine doing this is to modify all the functions I have that take in
> expressions (+ - * / let ...) and give them contracts that say "Hey,
> check to make sure your arguments are expressions, and if not, throw
> this syntax error!"

The only way to check whether a form is an expression or definition is
to partially expand it and match on the form.

In this case, maybe you want to report the error from the
implementation `func` by using `syntax-local-context` to detect when
it's being used in an expression position.

-- 
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] Is there a way to check whether syntax is an expression or a define statement?

2017-06-29 Thread Sam Waxman
On Thursday, June 29, 2017 at 11:22:38 AM UTC-4, David K. Storrs wrote:
> On Thu, Jun 29, 2017 at 11:10 AM, Sam Waxman  wrote:
> Hey all,
> 
> 
> 
> I'm writing a #lang and am trying to raise my own errors instead of having 
> racket throw any errors of its own.
> 
> 
> 
> One of my constructs, (func name(args) body), defines a function that's able 
> to be called afterwards, and it desugars into a pretty regular define 
> statement. As a result, I can't do things like
> 
> 
> 
> (let () (func a(x) x))
> 
> (+ (func a(x) x) 1)
> 
> etc ...
> 
> 
> 
> because it ends up expanding into a define statement in an expression 
> position, which is bad.
> 
> 
> 
> While I don't want this to be allowed, I'd like to catch this and throw my 
> own errors if this happens. The only way I can really imagine doing this is 
> to modify all the functions I have that take in expressions (+ - * / let ...)
> 
> and give them contracts that say "Hey, check to make sure your arguments are 
> expressions, and if not, throw this syntax error!"
> 
> 
> 
> The only problem there is that I can't seem to find any function that will 
> tell me if I have an expression or a define. Is there an easy way to check 
> this? I.e. a function expression? such that
> 
> 
> 
> (expression? #'(+ 1 1)); #t
> 
> (expression? #'(define a 1)); #f
> 
> (expression? #'(define-syntax-rule (id x) x)); #f
> 
> 
> 
> 
> 
> It'd be nice if there was a function like this, but also, if there's an 
> easier way to do this, by all means, lemme know!
> 
> 
> 
> Thanks in advance.
> 
> 
> 
> 
> 
> I think you want 'splicing-let':
> 
> #lang racket
> 
> (require racket/splicing)
> 
> (splicing-let ()
>   (define (foo a) a)
>   (foo 'x))
> (foo 'y)
> 
> 
> Ouput:
> 
> 
> 'x
> 
> 'y
> 
>  I'm not actually trying to get the define statements to define things here, 
> or to splice them into the surrounding environment, I'm just trying to throw 
> my own custom error messages/define my own custom behavior when you put 
> defines in expression positions. So

(my+ 1 (func a(x) x))

shouldn't work, but instead of racket's error messages, I'd like to throw one 
like "The arguments to + must be expressions. Recieved a function definition 
for argument 2."

I'd also be interested in changing (my-let () (func a(x) x)) to expand into 
(my-let () (func a(x) x) (values)) so racket doesn't throw an error when func's 
are the final bodies in a let statement.

But the issue isn't that I want to splice these defines, it's that I need a way 
of checking in my+, my-let, my-, my/ ... (which are all macros I've written for 
my languages' +, let, -, / ...) to see if the arguments they have are 
expressions or define statements.
> --
> 
> 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...@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] Defining new exception types with guards and default messages

2017-06-29 Thread David Storrs
Good to know.  I'll do it that way.

On Thu, Jun 29, 2017 at 11:26 AM, Philip McGrath 
wrote:

> Note, though, (having tried this) that putting a contract on the guard
> will give you undesirable blame behavior unless you use any/c for all the
> domain contracts as Matthias did. The guard must be able to accept all
> arguments, so the server module will be blamed if a client calls the
> constructor with values that violate the domain portion of the contract.
>
> -Philip
>
> On Thu, Jun 29, 2017 at 10:18 AM, David Storrs 
> wrote:
>
>>
>>
>> On Thu, Jun 29, 2017 at 9:50 AM, Matthias Felleisen > > wrote:
>>
>>>
>>> > On Jun 29, 2017, at 9:21 AM, David Storrs 
>>> wrote:
>>> >
>>> > I'd like to create a new exception type,
>>> 'exn:fail:insufficient-space', something like this:
>>> >
>>> > (struct exn:fail:insufficient-space exn:fail (requested available
>>> source))
>>> >
>>> > I would like to do two things:
>>> >
>>> > 1) Make the exn-message field be standardized so that the person
>>> throwing the exception doesn't need to (or, ideally, cannot) set it.
>>> >
>>> > 2) Apply a contract so that only valid arguments can be supplied.
>>> >
>>> > I could do both of these with a 'guard' statement and an external
>>> function definition:
>>> >
>>> > (define/contract (zot msg ccm req avail src type)
>>> >   (values "Insufficient space" ccm req avail src))
>>> > (struct exn:fail:insufficient-space exn:fail (requested available
>>> source)
>>> > #:guard zot)
>>> >
>>> > ...but this gives me a top-level definition that I don't want and need
>>> to remember to not export.
>>>
>>>
>>> I really think we should explicitly export bindings not implicitly.
>>> (all-defined-out) is a kludge.
>>>
>>>
>>> > I've been through the sections on contracts and local bindings and I
>>> don't see a way to apply one to a raw lamdba -- is there one?
>>>
>>>
>>> (struct exn:fail:insufficient-space exn:fail (requested available source)
>>>   #:guard
>>>   (local ((define/contract (zot msg   ccm   req   avail src   type)
>>> (-> any/c any/c any/c any/c any/c any/c (values string?
>>> any/c any/c any/c any/c))
>>> (values "Insufficient space" ccm req avail src)))
>>> zot))
>>>
>>>
>>>
>> Brilliant.  Thanks, Matthias.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> 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.


[racket-users] Testing #langs

2017-06-29 Thread Sam Waxman
Hey all,

I've been running into a lot of major roadblocks when it comes to writing good 
tests for some #langs that I've made, for a number of reasons.

Ideally, I want a function called
(check-eq-program? "program1" "program2")
That will run each program in a fresh module of my #lang, check what gets 
printed out, and compare them for equality.

I'm not quite sure how to write a function that creates and runs code in a 
fresh module though.

The fresh module is necessary for a number of reasons: If all of the programs 
worked in the same module, they would occasionally interfere with each other, 
as the #%module-begin's some of my #langs have initialize some "global 
variables" that need to be fresh/reinitialized every time a new program runs.

Some languages also work with continuations, and if they all ran in one module, 
would alter control flow so that only one program could ever run (they have 
aborts in odd places).

Ideally, the tests could be run in #lang racket instead of my own languages, so 
that the tests wouldn't be part of my language, so it probably makes sense that 
check-eq-program would have to take in a third argument for the language to use

(check-eq-program prog1 prog2 lang) Rackunit sadly does not seem to have 
anything good for these kinds of tests.

Can anyone offer some guidance on how to write a function like this, or if 
there's an easier way to go about this?

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.


Re: [racket-users] Defining new exception types with guards and default messages

2017-06-29 Thread Philip McGrath
Note, though, (having tried this) that putting a contract on the guard will
give you undesirable blame behavior unless you use any/c for all the domain
contracts as Matthias did. The guard must be able to accept all arguments,
so the server module will be blamed if a client calls the constructor with
values that violate the domain portion of the contract.

-Philip

On Thu, Jun 29, 2017 at 10:18 AM, David Storrs 
wrote:

>
>
> On Thu, Jun 29, 2017 at 9:50 AM, Matthias Felleisen 
> wrote:
>
>>
>> > On Jun 29, 2017, at 9:21 AM, David Storrs 
>> wrote:
>> >
>> > I'd like to create a new exception type, 'exn:fail:insufficient-space',
>> something like this:
>> >
>> > (struct exn:fail:insufficient-space exn:fail (requested available
>> source))
>> >
>> > I would like to do two things:
>> >
>> > 1) Make the exn-message field be standardized so that the person
>> throwing the exception doesn't need to (or, ideally, cannot) set it.
>> >
>> > 2) Apply a contract so that only valid arguments can be supplied.
>> >
>> > I could do both of these with a 'guard' statement and an external
>> function definition:
>> >
>> > (define/contract (zot msg ccm req avail src type)
>> >   (values "Insufficient space" ccm req avail src))
>> > (struct exn:fail:insufficient-space exn:fail (requested available
>> source)
>> > #:guard zot)
>> >
>> > ...but this gives me a top-level definition that I don't want and need
>> to remember to not export.
>>
>>
>> I really think we should explicitly export bindings not implicitly.
>> (all-defined-out) is a kludge.
>>
>>
>> > I've been through the sections on contracts and local bindings and I
>> don't see a way to apply one to a raw lamdba -- is there one?
>>
>>
>> (struct exn:fail:insufficient-space exn:fail (requested available source)
>>   #:guard
>>   (local ((define/contract (zot msg   ccm   req   avail src   type)
>> (-> any/c any/c any/c any/c any/c any/c (values string? any/c
>> any/c any/c any/c))
>> (values "Insufficient space" ccm req avail src)))
>> zot))
>>
>>
>>
> Brilliant.  Thanks, Matthias.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> 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] Is there a way to check whether syntax is an expression or a define statement?

2017-06-29 Thread David Storrs
On Thu, Jun 29, 2017 at 11:10 AM, Sam Waxman  wrote:

> Hey all,
>
> I'm writing a #lang and am trying to raise my own errors instead of having
> racket throw any errors of its own.
>
> One of my constructs, (func name(args) body), defines a function that's
> able to be called afterwards, and it desugars into a pretty regular define
> statement. As a result, I can't do things like
>
> (let () (func a(x) x))
> (+ (func a(x) x) 1)
> etc ...
>
> because it ends up expanding into a define statement in an expression
> position, which is bad.
>
> While I don't want this to be allowed, I'd like to catch this and throw my
> own errors if this happens. The only way I can really imagine doing this is
> to modify all the functions I have that take in expressions (+ - * / let
> ...)
> and give them contracts that say "Hey, check to make sure your arguments
> are expressions, and if not, throw this syntax error!"
>
> The only problem there is that I can't seem to find any function that will
> tell me if I have an expression or a define. Is there an easy way to check
> this? I.e. a function expression? such that
>
> (expression? #'(+ 1 1)); #t
> (expression? #'(define a 1)); #f
> (expression? #'(define-syntax-rule (id x) x)); #f
>
>
> It'd be nice if there was a function like this, but also, if there's an
> easier way to do this, by all means, lemme know!
>
> Thanks in advance.
>
>
I think you want 'splicing-let':

#lang racket

(require racket/splicing)

(splicing-let ()
  (define (foo a) a)
  (foo 'x))
(foo 'y)

Ouput:

'x
'y


> --
> 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] DrRacket Font Selection

2017-06-29 Thread Lehi Toskin
Now that I have figured out how to get `force-cache` to run through alternate 
means (using the scroll wheel) and have my preferred font selected, I think 
I'll be okay until a fix has been added. I think this started to happen when I 
upgraded to v6.9 and then downgraded to v6.8. I couldn't say *why*, but IIRC 
that also around the time when I started to have font issues.

-- 
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] Defining new exception types with guards and default messages

2017-06-29 Thread David Storrs
On Thu, Jun 29, 2017 at 9:50 AM, Matthias Felleisen 
wrote:

>
> > On Jun 29, 2017, at 9:21 AM, David Storrs 
> wrote:
> >
> > I'd like to create a new exception type, 'exn:fail:insufficient-space',
> something like this:
> >
> > (struct exn:fail:insufficient-space exn:fail (requested available
> source))
> >
> > I would like to do two things:
> >
> > 1) Make the exn-message field be standardized so that the person
> throwing the exception doesn't need to (or, ideally, cannot) set it.
> >
> > 2) Apply a contract so that only valid arguments can be supplied.
> >
> > I could do both of these with a 'guard' statement and an external
> function definition:
> >
> > (define/contract (zot msg ccm req avail src type)
> >   (values "Insufficient space" ccm req avail src))
> > (struct exn:fail:insufficient-space exn:fail (requested available source)
> > #:guard zot)
> >
> > ...but this gives me a top-level definition that I don't want and need
> to remember to not export.
>
>
> I really think we should explicitly export bindings not implicitly.
> (all-defined-out) is a kludge.
>
>
> > I've been through the sections on contracts and local bindings and I
> don't see a way to apply one to a raw lamdba -- is there one?
>
>
> (struct exn:fail:insufficient-space exn:fail (requested available source)
>   #:guard
>   (local ((define/contract (zot msg   ccm   req   avail src   type)
> (-> any/c any/c any/c any/c any/c any/c (values string? any/c
> any/c any/c any/c))
> (values "Insufficient space" ccm req avail src)))
> zot))
>
>
>
Brilliant.  Thanks, Matthias.

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


[racket-users] Is there a way to check whether syntax is an expression or a define statement?

2017-06-29 Thread Sam Waxman
Hey all,

I'm writing a #lang and am trying to raise my own errors instead of having 
racket throw any errors of its own.

One of my constructs, (func name(args) body), defines a function that's able to 
be called afterwards, and it desugars into a pretty regular define statement. 
As a result, I can't do things like

(let () (func a(x) x))
(+ (func a(x) x) 1)
etc ...

because it ends up expanding into a define statement in an expression position, 
which is bad.

While I don't want this to be allowed, I'd like to catch this and throw my own 
errors if this happens. The only way I can really imagine doing this is to 
modify all the functions I have that take in expressions (+ - * / let ...)
and give them contracts that say "Hey, check to make sure your arguments are 
expressions, and if not, throw this syntax error!"

The only problem there is that I can't seem to find any function that will tell 
me if I have an expression or a define. Is there an easy way to check this? 
I.e. a function expression? such that

(expression? #'(+ 1 1)); #t
(expression? #'(define a 1)); #f
(expression? #'(define-syntax-rule (id x) x)); #f


It'd be nice if there was a function like this, but also, if there's an easier 
way to do this, by all means, lemme know!

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.


Re: [racket-users] Defining new exception types with guards and default messages

2017-06-29 Thread Matthias Felleisen

> On Jun 29, 2017, at 9:21 AM, David Storrs  wrote:
> 
> I'd like to create a new exception type, 'exn:fail:insufficient-space', 
> something like this:
> 
> (struct exn:fail:insufficient-space exn:fail (requested available source))
> 
> I would like to do two things:
> 
> 1) Make the exn-message field be standardized so that the person throwing the 
> exception doesn't need to (or, ideally, cannot) set it.
> 
> 2) Apply a contract so that only valid arguments can be supplied.
> 
> I could do both of these with a 'guard' statement and an external function 
> definition:
> 
> (define/contract (zot msg ccm req avail src type)
>   (values "Insufficient space" ccm req avail src))
> (struct exn:fail:insufficient-space exn:fail (requested available source)
> #:guard zot)
> 
> ...but this gives me a top-level definition that I don't want and need to 
> remember to not export.


I really think we should explicitly export bindings not implicitly. 
(all-defined-out) is a kludge. 


> I've been through the sections on contracts and local bindings and I don't 
> see a way to apply one to a raw lamdba -- is there one?


(struct exn:fail:insufficient-space exn:fail (requested available source)
  #:guard
  (local ((define/contract (zot msg   ccm   req   avail src   type)
(-> any/c any/c any/c any/c any/c any/c (values string? any/c any/c 
any/c any/c))
(values "Insufficient space" ccm req avail src)))
zot))


-- 
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] Defining new exception types with guards and default messages

2017-06-29 Thread David Storrs
I'd like to create a new exception type, 'exn:fail:insufficient-space',
something like this:

(struct exn:fail:insufficient-space exn:fail (requested available source))

I would like to do two things:

1) Make the exn-message field be standardized so that the person throwing
the exception doesn't need to (or, ideally, cannot) set it.

2) Apply a contract so that only valid arguments can be supplied.

I could do both of these with a 'guard' statement and an external function
definition:

(define/contract (zot msg ccm req avail src type)
  (values "Insufficient space" ccm req avail src))
(struct exn:fail:insufficient-space exn:fail (requested available source)
#:guard zot)

...but this gives me a top-level definition that I don't want and need to
remember to not export. I've been through the sections on contracts and
local bindings and I don't see a way to apply one to a raw lamdba -- is
there one?

I also don't see a way to make it so that the fields inherited from the
superclass will default and not need to be specified by the caller.  There
is the 'struct-defaults' package but that is lacking documentation and I'm
not sure it works for defaulting the fields of a superclass.

-- 
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] Hint on opening enclosing directory of current file from DrRacket

2017-06-29 Thread Laurent
(yet another shameless self-promotion, but hopefully this can be of some
help.)

If you really want to add menu items for such small tasks, you can use the
script-plugin [1] which adds a easily modifiable Scripts menu item. There's
already a "Scripts/Utils/Open file directory" menu item there. Feedback
welcome :)

[1] https://pkgs.racket-lang.org/package/script-plugin

On Wed, Jun 28, 2017 at 10:42 PM, Glenn Hoetker  wrote:

> I hope this isn't painfully obvious to everyone but me, but I'd found it
> really frustrating until I found a solution. So, I thought I'd share. (If
> that's not appropriate traffic for the mailing list, I'd appreciate a more
> veteran hand letting me know. I'm still observing the norms.)
>
> Issue: While using DrRacket, I often want to open (in the Finder) the
> folder in which the current file is located. Many Mac applications allow
> one to do this with command-clicking the icon atop a window, but DrRacket
> doesn't. So, I need an alternative.
>
> Solution: Issue the command
>
>   (system "open .")
>
> from the Interaction window (one could do it from the Definition window,
> although I'm not sure why one would).
>
> Why it works (I think...): The documentation for "system" indicates that
> it operates in the current working directory unless otherwise directed.
> DrRacket sets, unless otherwise directed, the current working directory to
> the directory of the most recently run file. Since "." indicates the
> current directory, the command opens that directory.
>
> Caveats: 1. Since CWD is set to the most recently run file, you have to
> have run the file whose enclosing directory you wish to open. The default
> appears to the home directory. 2. I know this works on MacOS. I can't see
> why it wouldn't work on Unix systems. Windows scares me, so I have idea if
> it would work there.
>
> --
> 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.