Re: [racket-users] Routing syntax

2016-04-04 Thread Brian Adkins
On Apr 4, 2016, at 8:15 PM, David Vanderson  wrote:
> 
> On 04/04/2016 02:08 PM, Brian Adkins wrote:
>> (routes
>>   ("/" home-page)
>>   ("/:org_shortname/product_image/:style/:filename" product-image #:verbs 
>> (get)
>>#:name prod-image #:when (regexp-match #rx".jpg$" filename))
>>   ("/products/(*id).json" product-show #:verbs (get)))
>> 
>>  Any feedback is appreciated.
>> 
> Good start!  

Thanks :)

> One thing I liked about dispatch-rules is that it breaks the url parts up, so 
> you don't have to parse the string.  

My goal for the syntax is to make it as easy on the developer (i.e. user of the 
framework) as possible vs. being easy on me as the framework author. I expect 
the string can be parsed at compile time via a macro. I have to admit that in 
ten years of Rails development, I don't recall offhand ever having a parameter 
that wasn't an entire "node" of the URL, so my previous example of 
"/product/item-:id" may be a red herring. On the other hand, I don't see a 
reason to make that impossible. I do think I've used route globbing w/in a URL 
node, so I'd like to keep the string representation.

> If you could name them, then the part names could be racket identifiers in 
> scope, so you don't have misspelling issues in the #:when function.  

That should be able to be checked at compile time via a macro, right?

> I'm imagining that the route is essentially a match clause against a url 
> split by '/'.  Not sure if I'm making sense, but something like:

The url will split on '/', but nodes may be combined via globbing or a node may 
have a substring that's a parameter. For example:

"/products/(*id).json" e.g. /products/foo/bar/baz.json => id = 'foo/bar/baz' 

or "/product/item-:id" as mentioned above where /product/item-7 would result in 
id = '7'

> 
> (routes
>  (route ("")
> home-page)
>  (route (org_shortname "product_image" style filename)
> product-image
> #:name prod-image #:methods (get put)
> #:when (regexp-match #rx".jpg$" filename)))
> 
> Maybe there's a way to tag url parts with predicates, sort of like 
> dispatch-rules or syntax-parse, but it might obscure the url too much:
> 
> (route ((org_shortname string?)
>"product_image"
>(style number?)
>(filename (lambda () (regexp-match #rx".jpg$" filename
>   #:name prod-image #:methods (get put))
> 

I can think of a number of ways to make this much easier on myself, but as I 
mentioned, I'm trying to maximize ease for the framework user. Now, if I 
encounter serious roadblocks while implementing this, I may need to make 
concessions :)

> Hope this helps,
> Dave
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Racket Users" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/racket-users/wZ07AM8SBuw/unsubscribe.
> To unsubscribe from this group and all its topics, 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] Routing syntax

2016-04-04 Thread David Vanderson

On 04/04/2016 02:08 PM, Brian Adkins wrote:

(routes
   ("/" home-page)
   ("/:org_shortname/product_image/:style/:filename" product-image #:verbs (get)
#:name prod-image #:when (regexp-match #rx".jpg$" filename))
   ("/products/(*id).json" product-show #:verbs (get)))

  Any feedback is appreciated.

Good start!  One thing I liked about dispatch-rules is that it breaks 
the url parts up, so you don't have to parse the string.  If you could 
name them, then the part names could be racket identifiers in scope, so 
you don't have misspelling issues in the #:when function.  I'm imagining 
that the route is essentially a match clause against a url split by 
'/'.  Not sure if I'm making sense, but something like:


(routes
  (route ("")
 home-page)
  (route (org_shortname "product_image" style filename)
 product-image
 #:name prod-image #:methods (get put)
 #:when (regexp-match #rx".jpg$" filename)))

Maybe there's a way to tag url parts with predicates, sort of like 
dispatch-rules or syntax-parse, but it might obscure the url too much:


(route ((org_shortname string?)
"product_image"
(style number?)
(filename (lambda () (regexp-match #rx".jpg$" filename
   #:name prod-image #:methods (get put))

Hope this helps,
Dave

--
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 not W^X?

2016-04-04 Thread Matthew Flatt
At Mon, 4 Apr 2016 17:47:15 -0400, George Neuner wrote:
> On 4/4/2016 4:57 PM, 'John Clements' via users-redirect wrote:
> > FWIW, it appears that the restriction here is much simpler; 
> > specifically, pages can’t be writable and executable *simultaneously.* 
> > Moreover, a comment by Matthew on the github bug suggests that this 
> > might … have a relatively straightforward fix?
> 
> There are those who interpret W^X more severely as "once writable - 
> *never* executable".  That is fine for static loaded code and even for 
> generated interpreter code [because that is just data].   But this 
> severe interpretation of W^X is incompatible with runtime native code 
> generation.
> 
> I agree that the simpler "not simultaneously" interpretation is just a 
> performance issue: a kernel call to change protection costs many 
> thousands of executed instructions.  Obviously the overhead can be 
> amortized by changing more pages in a single call, but JIT systems that 
> compile in small units: e.g., function by function as they are 1st 
> called - may suffer significant performance loss.  [An issue now that 
> CPU cores aren't getting any faster.]

There's another issue, which is that a thread might be executing JITted
code while new code is bring written. Since, as you note, units of JIT
generation tend to be smaller than a page, this creates trouble if
JITted code running in one thread is allocated on the same page as
JITting in progress in another thread. Closures for callbacks via
libffi have the same problem.

It looks like libffi solves the problem by

 * creating a temporary file F;

 * mapping a region of F to executable memory; and

 * mapping the same region of F to writable memory.

So, write to the latter address, and the code at the former address
changes. (At this point, I've definitely lost track of what problem
"W^X" is supposed to solve.)

I think the JIT can be adapted to this strategy, but it will require
threading both write and execute pointers through the implementation
and adjusting some GC interactions. Maybe it won't be difficult, and
maybe I'll try eventually. Meanwhile, a pull request would be welcome.

-- 
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 not W^X?

2016-04-04 Thread George Neuner

On 4/4/2016 4:57 PM, 'John Clements' via users-redirect wrote:
FWIW, it appears that the restriction here is much simpler; 
specifically, pages can’t be writable and executable *simultaneously.* 
Moreover, a comment by Matthew on the github bug suggests that this 
might … have a relatively straightforward fix?


There are those who interpret W^X more severely as "once writable - 
*never* executable".  That is fine for static loaded code and even for 
generated interpreter code [because that is just data].   But this 
severe interpretation of W^X is incompatible with runtime native code 
generation.


I agree that the simpler "not simultaneously" interpretation is just a 
performance issue: a kernel call to change protection costs many 
thousands of executed instructions.  Obviously the overhead can be 
amortized by changing more pages in a single call, but JIT systems that 
compile in small units: e.g., function by function as they are 1st 
called - may suffer significant performance loss.  [An issue now that 
CPU cores aren't getting any faster.]


YMMV,
George

--
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 not W^X?

2016-04-04 Thread 'John Clements' via users-redirect

> On Apr 2, 2016, at 1:40 PM, Jos Koot  wrote:
> 
> A compiler produces code (in this phase data) that can be executed.
> Babbage started with a machine that made distinction between program and
> data.
> In a Von Neuman machine there is no distinction between data and programs.
> In lambda calculus neither.
> Say you have a program that allows the user to answer questions
> and assume the program behaves differently depending on the answers.
> Are the answers just data or do they form a program?
> Executable code can be data and reversely.
> What do you want your computer to do when ordering it to copy a program?
> What should DrRacket do when you ask it to prepare an executable file?
> Although in general it is wise to make a distinction between program and
> data,
> ultimately enforcing this distinction would prohibit avanced programs.
> My 2 (or may be only 1) cents.
> Jos

FWIW, it appears that the restriction here is much simpler; specifically, pages 
can’t be writable and executable *simultaneously.* Moreover, a comment by 
Matthew on the github bug suggests that this might … have a relatively 
straightforward fix?

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] Case and eof

2016-04-04 Thread Jon Zeppieri
On Mon, Apr 4, 2016 at 3:40 PM, Jay McCarthy  wrote:

> case is just for integers and symbols.
>


I'm not sure if you meant this as a claim about how you think `case` should
be used, but it certainly does work for more than just integers and
symbols. It will work for any data with a literal reader syntax. -J

-- 
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] Case and eof

2016-04-04 Thread Alex Knauth

> On Apr 4, 2016, at 3:40 PM, Jay McCarthy  wrote:

> (member eof '(eof)) is #f
> 
> Because '(eof) is the same as (list 'eof) NOT (list eof)
> 
> Jay

I'm convinced that implicit quotes are the root of almost all evil in lisp 
programming languages. That's a big reason why I like the teaching languages 
better in terms of things making sense.

It's also why I normally use `match` instead of `case` even when I *am* dealing 
with integers or symbols.

Alex Knauth

> On Mon, Apr 4, 2016 at 3:34 PM, rom cgb  wrote:
>> Hi,
>> 
>> Trying to use eof in a case expression but it doesn't work.
>> 
>> For example
>> 
>>(define (test x)
>>  (case x
>>[(eof) eof]
>>[else  "else"]))
>> 
>> 
>> (test eof) will then evaluate to "else" despite (equal? eof eof) evaluating 
>> to #t.
>> 
>> Why ?

-- 
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: Case and eof

2016-04-04 Thread Jens Axel Søgaard
Btw - if you like to use case, you could try the old evcase instead:

http://docs.racket-lang.org/mzlib/mzlib_etc.html?q=evcase#%28form._%28%28lib._mzlib%2Fetc..rkt%29._evcase%29%29

2016-04-04 22:36 GMT+02:00 rom cgb :

> I see, that's why it also does work with string constants. 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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: Case and eof

2016-04-04 Thread rom cgb
I see, that's why it also does work with string constants. 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] Routing syntax

2016-04-04 Thread Brian Adkins
> On Apr 4, 2016, at 3:44 PM, antoine  wrote:
> 
> Hello,
> 
> I would go for 'methods instead of 'verbs, a HTTP vocabulary instead of a 
> REST one.

Fair point. I suppose a couple additional characters won't kill me.

> For the pathinfo:
> 
> When using a string you use :pattern as place holder as far as i know there 
> is no such convention in racket, maybe you should explore ~pattern (like 
> format), #:pattern, 'pattern, #'pattern (like macro templating) or at-expr?

I'm open to other ideas, but :variable is used in a number of routing string 
patterns in other languages/frameworks and seems fairly standard.

> For constraints on placeholders you may want to limit them to regexp because:
> 
> 1. 99.999% of the time they will satisfy the developer needs.
> 2. You give you room to make your router fast implementing a minimal final 
> state machine (a regexp).

I'm not sure I understand how *limiting* the constraint to be a regex is faster 
than *allowing* the constraint to be a regex i.e. in either case, the URL needs 
to be parsed and then a function called to compare a variable to a regex 
pattern. Am I misunderstanding?

I probably didn't communicate very well with my example, but when I first 
started thinking about constraints, I assumed I'd follow the Rails idea of an 
elaborate construct to declare all the constraints, but then I thought that 
using a single lambda to indicate whether the route matched might be better. I 
figured syntax sugar can be added later for common cases. For example:

("/:org_shortname/product_image/:style/:filename" product-image 
 #:methods get
 #:when verify-filename)

(define (verify-filename params)
  (regexp-match #rx".jpg$" (hash-ref params 'filename)))

or

("/:org_shortname/product_image/:style/:filename" product-image 
 #:methods get
 #:when verify-filename-and-style)

(define (verify-filename-and-style params)
  (and
(regexp-match #rx".jpg$" (hash-ref params 'filename))
(exact-integer? (hash-ref params 'style

> example:
> 
> ("/~org-shortname/product_image/~style/~filename"
> #:method POST
> #:constraints ([filename ".*\\.xml$"])
> ;; a guard that break optimisations and expand
> #:when (not (equal? "abc" org-shortname))
> #:controller my-controller)

I'm not sure what you're suggesting here. Is your idea to provide both 
#:constraints and #:when ?

> Or maybe use a list like dispatch-rule
> 
> ((org-shortname "product_image" style filename)
> #:method POST
> #:constraints ([filename ".*\\.xml$"])
> ;; a guard that break optimisations and expand
> #:when (not (equal? "abc" org-shortname))
> #:controller my-controller)

The list style might disallow something like:  

"/product/item-:id" e.g. /product/item-473

or

"/products/(*id).json" e.g. /products/foo/bar/baz.json => id = 'foo/bar/baz'

> On 04/04/2016 08:08 PM, Brian Adkins wrote:
>> I've been looking into an appropriate syntax for routing web requests. For 
>> each route, I'll need the following information:
>> 
>> * URL Pattern (required) e.g.
>>   "/"
>>   "/:org_shortname/product_image/:style/:filename"
>>   "/:org_shortname/products/(*id).json"
>> 
>> * Function to handle request (required)
>> 
>> * Accepted HTTP verbs (optional, defaults ot all)
>> 
>> * Name (optional) - used to do "reverse routing" i.e. produce a URL from 
>> parameters
>> 
>> * Contraints (optional) - further refine the pattern matching e.g. 
>> type/format of params
>> 
>> Here's an example from Rails:
>> 
>> Foo::Application.routes.draw do
>>   match "/:org_shortname/product_image/:style/:filename" => 
>> 'product_images#product_image',
>> :as => :product_image, :via => :get, :constraints => { :filename => 
>> /.jpg$/ }
>> 
>>   # URL pattern: "/:org_shortname/product_image/:style/:filename"
>>   # Function: ProductImagesController.product_image
>>   # Name: :product_image
>>   # Verbs: GET
>>   # Contraints: filename param must end in .jpg
>> 
>>   match '/products/(*id).json'  => 'products#show', :via => :get
>> 
>>   # URL pattern: '/products/(*id).json'
>>   #(*id) globs everything between /products/ and .json including / chars
>>   # Function: ProductsController.show
>>   # Verbs: GET
>> end
>> 
>> There are many other aspects (much of which is just syntax sugar) of routing 
>> in Rails that I'm ignoring initially.
>> 
>> I'm thinking of something like the following:
>> 
>> (routes
>>   ("/" home-page)
>>   ("/:org_shortname/product_image/:style/:filename" product-image #:verbs 
>> (get)
>>#:name prod-image #:when (regexp-match #rx".jpg$" filename))
>>   ("/products/(*id).json" product-show #:verbs (get)))
>> 
>> The first two arguments (url-pattern function) are required, so they're 
>> positional. The optional arguments are specified with keywords.
>> 
>> Instead of:  #:verbs (get)would it be better to have  #:verbs get  and 
>> dynamically check for an atom vs. list ?
>> 
>> My initial goal is just for the "base" syntax. Sugar can be added later for 
>> some cases.
>> 

Re: [racket-users] How to call a macro on each element of a list

2016-04-04 Thread 'John Clements' via Racket Users

> On Mar 31, 2016, at 3:31 PM, cna...@cs.washington.edu wrote:
> 
> On Thursday, March 31, 2016 at 1:00:55 AM UTC-7, cna...@cs.washington.edu 
> wrote:
>> On Wednesday, March 30, 2016 at 5:37:08 PM UTC-7, Neil Van Dyke wrote:
> 
> I found a solution to my problem. I realised that it was better to use a 
> function instead of a macro to generate the code. I created a list and 
> appended the different parts of the code I wanted to generate in bottom up 
> manner. eval-ing the list can run the code. 

Speaking *only for myself*:

In a situation such as the one you describe, I’m about 86% confident that 
there’s no need for ‘eval’ *or* a macro. As Neil points out, ‘eval’ comes with 
substantial risks and development costs.

Naturally, if you’ve got something that works, I understand that it may make 
more sense to stick with that.

John Clements



-- 
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] Routing syntax

2016-04-04 Thread Brian Adkins
On Monday, April 4, 2016 at 3:39:13 PM UTC-4, Matt Jadud wrote:
> Hi Brian,
> 
> 
> This looks similar to what "dispatch" does?
> 
> 
> https://docs.racket-lang.org/web-server/dispatch.html
> 
> 
> 
> I've never extended the bi-directional patterns that are available, but there 
> is an extension mechanism built in, so that your #:when notions might be part 
> of an extended/new url component matcher?
> 
> 
> Cheers,
> M

They both have a similar role, but I think there are significant differences 
(unless I'm misunderstanding):

* It's not uncommon to rearrange the components of a URL pattern. Without name 
binding, you would need to change both the pattern and the handler function.

* Typing is optional for mine

* I didn't see a way to define further constraints (besides the type of an 
argument) i.e. ensuring an argument matches a pattern

I thought about not providing the #:name parameter, and that might be possible. 
Rails provides name_url() and name)_path() functions for absolute and relative 
url creation - I'll have to weigh the pros/cons of using the name of the 
handler function as the prefix for those.

-- 
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] Case and eof

2016-04-04 Thread Jens Axel Søgaard
2016-04-04 21:34 GMT+02:00 rom cgb :

> Hi,
>
> Trying to use eof in a case expression but it doesn't work.
>
> For example
>
> (define (test x)
>   (case x
> [(eof) eof]
> [else  "else"]))
>
>
> (test eof) will then evaluate to "else" despite (equal? eof eof)
> evaluating to #t.
>
> Why ?


The (eof) clause in case is a list of datums. That means case
will taste for the symbol eof and not the end of file object.

(case 'eof
  [(eof) 42])   ; 42

(case eof
  [(eof) 42]
  [else  #f])  ; #f

Instead use cond
  (cond
[(eof-object? x) ...]
[else  #f])

/Jens Axel





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



-- 
-- 
Jens Axel Søgaard

-- 
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] Routing syntax

2016-04-04 Thread antoine

Hello,

I would go for 'methods instead of 'verbs, a HTTP vocabulary instead of 
a REST one.


For the pathinfo:

When using a string you use :pattern as place holder as far as i know 
there is no such convention in racket, maybe you should explore ~pattern 
(like format), #:pattern, 'pattern, #'pattern (like macro templating) or 
at-expr?


For constraints on placeholders you may want to limit them to regexp 
because:


1. 99.999% of the time they will satisfy the developer needs.
2. You give you room to make your router fast implementing a minimal 
final state machine (a regexp).


example:

("/~org-shortname/product_image/~style/~filename"
 #:method POST
 #:constraints ([filename ".*\\.xml$"])
 ;; a guard that break optimisations and expand
 #:when (not (equal? "abc" org-shortname))
 #:controller my-controller)


Or maybe use a list like dispatch-rule

((org-shortname "product_image" style filename)
 #:method POST
 #:constraints ([filename ".*\\.xml$"])
 ;; a guard that break optimisations and expand
 #:when (not (equal? "abc" org-shortname))
 #:controller my-controller)




On 04/04/2016 08:08 PM, Brian Adkins wrote:

I've been looking into an appropriate syntax for routing web requests. For each 
route, I'll need the following information:

* URL Pattern (required) e.g.
   "/"
   "/:org_shortname/product_image/:style/:filename"
   "/:org_shortname/products/(*id).json"

* Function to handle request (required)

* Accepted HTTP verbs (optional, defaults ot all)

* Name (optional) - used to do "reverse routing" i.e. produce a URL from 
parameters

* Contraints (optional) - further refine the pattern matching e.g. type/format 
of params

Here's an example from Rails:

Foo::Application.routes.draw do
   match "/:org_shortname/product_image/:style/:filename" => 
'product_images#product_image',
 :as => :product_image, :via => :get, :constraints => { :filename => 
/.jpg$/ }

   # URL pattern: "/:org_shortname/product_image/:style/:filename"
   # Function: ProductImagesController.product_image
   # Name: :product_image
   # Verbs: GET
   # Contraints: filename param must end in .jpg

   match '/products/(*id).json'  => 'products#show', :via => :get

   # URL pattern: '/products/(*id).json'
   #(*id) globs everything between /products/ and .json including / chars
   # Function: ProductsController.show
   # Verbs: GET
end

There are many other aspects (much of which is just syntax sugar) of routing in 
Rails that I'm ignoring initially.

I'm thinking of something like the following:

(routes
   ("/" home-page)
   ("/:org_shortname/product_image/:style/:filename" product-image #:verbs (get)
#:name prod-image #:when (regexp-match #rx".jpg$" filename))
   ("/products/(*id).json" product-show #:verbs (get)))

The first two arguments (url-pattern function) are required, so they're 
positional. The optional arguments are specified with keywords.

Instead of:  #:verbs (get)would it be better to have  #:verbs get  and 
dynamically check for an atom vs. list ?

My initial goal is just for the "base" syntax. Sugar can be added later for 
some cases.

  Any feedback is appreciated.

Thanks,
Brian



--
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] Case and eof

2016-04-04 Thread Jay McCarthy
case is just for integers and symbols.

(case x [(eof) eof] [else "else"])

is equivalent to

(cond [(member x '(eof)) eof] [else "else"])

and

(member eof '(eof)) is #f

Because '(eof) is the same as (list 'eof) NOT (list eof)

Jay


On Mon, Apr 4, 2016 at 3:34 PM, rom cgb  wrote:
> Hi,
>
> Trying to use eof in a case expression but it doesn't work.
>
> For example
>
> (define (test x)
>   (case x
> [(eof) eof]
> [else  "else"]))
>
>
> (test eof) will then evaluate to "else" despite (equal? eof eof) evaluating 
> to #t.
>
> Why ?
>
>
>
> --
> 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.



-- 
Jay McCarthy
Associate Professor
PLT @ CS @ UMass Lowell
http://jeapostrophe.github.io

   "Wherefore, be not weary in well-doing,
  for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
  - D 64:33

-- 
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] Routing syntax

2016-04-04 Thread Matt Jadud
Hi Brian,

This looks similar to what "dispatch" does?

https://docs.racket-lang.org/web-server/dispatch.html

I've never extended the bi-directional patterns that are available, but
there is an extension mechanism built in, so that your #:when notions might
be part of an extended/new url component matcher?

Cheers,
M



On Mon, Apr 4, 2016 at 2:08 PM, Brian Adkins  wrote:

> I've been looking into an appropriate syntax for routing web requests. For
> each route, I'll need the following information:
>
> * URL Pattern (required) e.g.
>   "/"
>   "/:org_shortname/product_image/:style/:filename"
>   "/:org_shortname/products/(*id).json"
>
> * Function to handle request (required)
>
> * Accepted HTTP verbs (optional, defaults ot all)
>
> * Name (optional) - used to do "reverse routing" i.e. produce a URL from
> parameters
>
> * Contraints (optional) - further refine the pattern matching e.g.
> type/format of params
>
> Here's an example from Rails:
>
> Foo::Application.routes.draw do
>   match "/:org_shortname/product_image/:style/:filename" =>
> 'product_images#product_image',
> :as => :product_image, :via => :get, :constraints => { :filename =>
> /.jpg$/ }
>
>   # URL pattern: "/:org_shortname/product_image/:style/:filename"
>   # Function: ProductImagesController.product_image
>   # Name: :product_image
>   # Verbs: GET
>   # Contraints: filename param must end in .jpg
>
>   match '/products/(*id).json'  => 'products#show', :via => :get
>
>   # URL pattern: '/products/(*id).json'
>   #(*id) globs everything between /products/ and .json including /
> chars
>   # Function: ProductsController.show
>   # Verbs: GET
> end
>
> There are many other aspects (much of which is just syntax sugar) of
> routing in Rails that I'm ignoring initially.
>
> I'm thinking of something like the following:
>
> (routes
>   ("/" home-page)
>   ("/:org_shortname/product_image/:style/:filename" product-image #:verbs
> (get)
>#:name prod-image #:when (regexp-match #rx".jpg$" filename))
>   ("/products/(*id).json" product-show #:verbs (get)))
>
> The first two arguments (url-pattern function) are required, so they're
> positional. The optional arguments are specified with keywords.
>
> Instead of:  #:verbs (get)would it be better to have  #:verbs get  and
> dynamically check for an atom vs. list ?
>
> My initial goal is just for the "base" syntax. Sugar can be added later
> for some cases.
>
>  Any feedback is appreciated.
>
> Thanks,
> Brian
>
> --
> 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] Case and eof

2016-04-04 Thread rom cgb
Hi,

Trying to use eof in a case expression but it doesn't work.

For example

(define (test x)
  (case x
[(eof) eof]
[else  "else"]))


(test eof) will then evaluate to "else" despite (equal? eof eof) evaluating to 
#t. 

Why ?



-- 
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] Routing syntax

2016-04-04 Thread Brian Adkins
I've been looking into an appropriate syntax for routing web requests. For each 
route, I'll need the following information:

* URL Pattern (required) e.g.
  "/"
  "/:org_shortname/product_image/:style/:filename"
  "/:org_shortname/products/(*id).json"

* Function to handle request (required)

* Accepted HTTP verbs (optional, defaults ot all)

* Name (optional) - used to do "reverse routing" i.e. produce a URL from 
parameters

* Contraints (optional) - further refine the pattern matching e.g. type/format 
of params

Here's an example from Rails:

Foo::Application.routes.draw do
  match "/:org_shortname/product_image/:style/:filename" => 
'product_images#product_image',
:as => :product_image, :via => :get, :constraints => { :filename => /.jpg$/ 
}

  # URL pattern: "/:org_shortname/product_image/:style/:filename"
  # Function: ProductImagesController.product_image
  # Name: :product_image
  # Verbs: GET
  # Contraints: filename param must end in .jpg

  match '/products/(*id).json'  => 'products#show', :via => :get

  # URL pattern: '/products/(*id).json'
  #(*id) globs everything between /products/ and .json including / chars
  # Function: ProductsController.show
  # Verbs: GET
end

There are many other aspects (much of which is just syntax sugar) of routing in 
Rails that I'm ignoring initially.

I'm thinking of something like the following:

(routes
  ("/" home-page)
  ("/:org_shortname/product_image/:style/:filename" product-image #:verbs (get)
   #:name prod-image #:when (regexp-match #rx".jpg$" filename))
  ("/products/(*id).json" product-show #:verbs (get)))

The first two arguments (url-pattern function) are required, so they're 
positional. The optional arguments are specified with keywords.

Instead of:  #:verbs (get)would it be better to have  #:verbs get  and 
dynamically check for an atom vs. list ?

My initial goal is just for the "base" syntax. Sugar can be added later for 
some cases.

 Any feedback is appreciated.

Thanks,
Brian

-- 
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] FFI | Unions

2016-04-04 Thread Pedro Caldeira
> No. Racket's evaluation model doesn't include the notion of an
> allocation stack that is associated with a continuation.
> 
> You could implement some form of stack manually, but heap allocation
> (especially as managed by the GC) is usually the way to go.

I see, so Racket only stores a reference. However we still need to use the 
union-ptr procedure when using the union as a pointer parameter in a foreign 
function, right? Why is that?

Thank you again for your previous reply.

-- 
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] FFI | Unions

2016-04-04 Thread Matthew Flatt
At Sat, 2 Apr 2016 12:18:45 -0700 (PDT), Pedro Caldeira wrote:
> The way you've proposed allocates the union on the heap, is it
> possible to declare an union on the stack?

No. Racket's evaluation model doesn't include the notion of an
allocation stack that is associated with a continuation.

You could implement some form of stack manually, but heap allocation
(especially as managed by the GC) is usually the way to go.

-- 
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] JTRES 2016 Call for Papers

2016-04-04 Thread Andrea Rosà
==

CALL FOR PAPERS

  The 14th Workshop on
   Java Technologies for Real-Time and Embedded Systems
   JTRES 2016

  Part of the
 Managed Languages & Runtimes Week 2016
   29 August - 2 September 2016
 Lugano, Switzerland

  http://jtres2016.compute.dtu.dk/


==

Submission deadline: 12 June, 2016
Submission site: https://easychair.org/conferences/?conf=jtres2016

==

Over 90% of all microprocessors are now used for real-time and embedded 
applications. Embedded devices are deployed on a broad diversity of distinct 
processor architectures and operating systems. The application software for 
many embedded devices is custom tailored if not written entirely from scratch. 
The size of typical embedded system software applications is growing 
exponentially from year to year, with many of today's embedded systems 
comprised of multiple millions of lines of code. For all of these reasons, the 
software portability, reuse, and modular composability benefits offered by Java 
are especially valuable to developers of embedded systems.

Both embedded and general-purpose software frequently need to comply with 
real-time constraints. Higher-level programming languages and middleware are 
needed to robustly and productively design, implement, compose, integrate, 
validate, and enforce memory and real-time constraints along with conventional 
functional requirements for reusable software components. The Java programming 
language has become an attractive choice because of its safety, productivity, 
its relatively low maintenance costs, and the availability of well-trained 
developers.

::Goal::

Interest in real-time Java by both the academic research community and 
commercial industry has been motivated by the need to manage the complexity and 
costs associated with continually expanding embedded real-time software 
systems. The goal of the workshop is to gather researchers working on real-time 
and embedded Java to identify the challenging problems that still need to be 
solved in order to assure the success of real-time Java as a technology and to 
report results and experience gained by researchers.

The Java ecosystem has outgrown the combination of Java as programming language 
and the JVM. For example, Android uses Java as source language and the Dalvik 
virtual machine for execution. Languages such as Scala are compiled to Java 
bytecode and executed on the JVM. JTRES welcomes submissions that apply such 
approaches to embedded and/or real-time systems.

::Submission Requirements::

Participants are expected to submit a paper of at most 10 pages (ACM Conference 
Format, i.e., two-columns, 10 point font). Accepted papers will be published in 
the ACM International Conference Proceedings Series via the ACM Digital Library 
and have to be presented by one author at the JTRES.

LaTeX and Word templates can be found at: 
http://www.acm.org/sigs/pubs/proceed/template.html

Papers describing open source projects shall include a description how to 
obtain the source and how to run the experiments in the appendix. The source 
version for the published paper will be hosted at the JTRES web site.
Papers should be submitted through EasyChair. Please use the submission link:
https://easychair.org/conferences/?conf=jtres2016

Selected papers will be invited for submission to a special issue of the TBD.

Topics of interest to this workshop include, but are not limited to:

New real-time programming paradigms and language features
Industrial experience and practitioner reports
Open source solutions for real-time Java
Real-time design patterns and programming idioms
High-integrity and safety critical system support
Java-based real-time operating systems and processors
Extensions to the RTSJ and SCJ
Real-time and embedded virtual machines and execution environments
Memory management and real-time garbage collection
Multiprocessor and distributed real-time Java
Real-time solutions for Android
Languages other than Java on real-time or embedded JVMs
Benchmarks and Open Source applications using real-time Java

::Important Dates::

Paper Submission: 12 June, 2016
Notification of Acceptance: 20 July, 2016
Camera Ready Paper Due: 15 August, 2016
Workshop: 29 August - 2 September, 2016

::Program Chair::

Martin Schoeberl, Technical University of Denmark

::Workshop Chair::

Walter Binder, University of Lugano (USI), Switzerland

::Program Committee Members::

Ethan Blanton, Fiji Systems Inc
Ana Cavalcanti, University of York
Peter Dibble, RTSJ
M. Teresa Higuera-Toledano, Universidad