[racket-users] Re: Official Docker images for Racket

2015-09-04 Thread Jack Firth
> 
> Virtualbox -> Linux -> Docker -> Alpine
>^
> 
> Which Linux distro?
> 
> I'm asking because the usual Racket errors in distros with grsecurity 
> are pretty easy to workaround. These errors affect to every JIT, not 
> only to Racket.
> 
> If you're running a non-grsecurity kernel in the host OS, then the 
> problems are probably related to musl. It would require to patch the 
> Racket interpreter.

>From what I can gather, it's using a modified TinyCore linux through the 
>boot2docker driver 
>https://github.com/boot2docker/boot2docker/blob/master/doc/FAQ.md#what-is-the-boot2docker-distribution-based-on

-- 
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: Official Docker images for Racket

2015-09-04 Thread Juan Francisco Cantero Hurtado

On 09/04/2015 07:29 PM, Jack Firth wrote:

On Friday, September 4, 2015 at 10:27:12 AM UTC-7, Jack Firth wrote:

On Friday, September 4, 2015 at 8:23:14 AM UTC-7, Juan Francisco Cantero 
Hurtado wrote:

On 09/04/2015 04:59 PM, Jack Firth wrote:

On Friday, September 4, 2015 at 4:51:43 AM UTC-7, Juan Francisco Cantero 
Hurtado wrote:

On 09/03/2015 08:07 AM, Jack Firth wrote:

I've attempted to compile from source in an alpine image, but with no success. 
There's a bit too much arcane magic there for me to figure out how to do that.



Can you show the errors on Alpine? Are you using Alpine in a container
or in a virtual/real machine?.

Alpine is interesting because they use grsecurity and musl.


I've got my attempt in the repo now under the 6.2-min folder. Furthest I've gotten - install 
dev tools including C compiler, download source, run ./configure && make && 
make install, and watch errors show up.


Which OS is running the host?


OS X Yosemite 10.10.5.


Wait, scratch that. That's the machine I'm working on, but it's running the 
Docker daemon in a linux virtual box.



Virtualbox -> Linux -> Docker -> Alpine
  ^

Which Linux distro?

I'm asking because the usual Racket errors in distros with grsecurity 
are pretty easy to workaround. These errors affect to every JIT, not 
only to Racket.


If you're running a non-grsecurity kernel in the host OS, then the 
problems are probably related to musl. It would require to patch the 
Racket interpreter.


--
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: Official Docker images for Racket

2015-09-04 Thread Jack Firth
On Friday, September 4, 2015 at 10:27:12 AM UTC-7, Jack Firth wrote:
> On Friday, September 4, 2015 at 8:23:14 AM UTC-7, Juan Francisco Cantero 
> Hurtado wrote:
> > On 09/04/2015 04:59 PM, Jack Firth wrote:
> > > On Friday, September 4, 2015 at 4:51:43 AM UTC-7, Juan Francisco Cantero 
> > > Hurtado wrote:
> > >> On 09/03/2015 08:07 AM, Jack Firth wrote:
> > >>> I've attempted to compile from source in an alpine image, but with no 
> > >>> success. There's a bit too much arcane magic there for me to figure out 
> > >>> how to do that.
> > >>>
> > >>
> > >> Can you show the errors on Alpine? Are you using Alpine in a container
> > >> or in a virtual/real machine?.
> > >>
> > >> Alpine is interesting because they use grsecurity and musl.
> > >
> > > I've got my attempt in the repo now under the 6.2-min folder. Furthest 
> > > I've gotten - install dev tools including C compiler, download source, 
> > > run ./configure && make && make install, and watch errors show up.
> > 
> > Which OS is running the host?
> 
> OS X Yosemite 10.10.5.

Wait, scratch that. That's the machine I'm working on, but it's running the 
Docker daemon in a linux virtual box.

-- 
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: Official Docker images for Racket

2015-09-04 Thread Jack Firth
On Friday, September 4, 2015 at 8:23:14 AM UTC-7, Juan Francisco Cantero 
Hurtado wrote:
> On 09/04/2015 04:59 PM, Jack Firth wrote:
> > On Friday, September 4, 2015 at 4:51:43 AM UTC-7, Juan Francisco Cantero 
> > Hurtado wrote:
> >> On 09/03/2015 08:07 AM, Jack Firth wrote:
> >>> I've attempted to compile from source in an alpine image, but with no 
> >>> success. There's a bit too much arcane magic there for me to figure out 
> >>> how to do that.
> >>>
> >>
> >> Can you show the errors on Alpine? Are you using Alpine in a container
> >> or in a virtual/real machine?.
> >>
> >> Alpine is interesting because they use grsecurity and musl.
> >
> > I've got my attempt in the repo now under the 6.2-min folder. Furthest I've 
> > gotten - install dev tools including C compiler, download source, run 
> > ./configure && make && make install, and watch errors show up.
> 
> Which OS is running the host?

OS X Yosemite 10.10.5.

-- 
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: Official Docker images for Racket

2015-09-04 Thread Juan Francisco Cantero Hurtado

On 09/04/2015 04:59 PM, Jack Firth wrote:

On Friday, September 4, 2015 at 4:51:43 AM UTC-7, Juan Francisco Cantero 
Hurtado wrote:

On 09/03/2015 08:07 AM, Jack Firth wrote:

I've attempted to compile from source in an alpine image, but with no success. 
There's a bit too much arcane magic there for me to figure out how to do that.



Can you show the errors on Alpine? Are you using Alpine in a container
or in a virtual/real machine?.

Alpine is interesting because they use grsecurity and musl.


I've got my attempt in the repo now under the 6.2-min folder. Furthest I've gotten - install 
dev tools including C compiler, download source, run ./configure && make && 
make install, and watch errors show up.


Which OS is running the host?


--
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: Official Docker images for Racket

2015-09-04 Thread Jack Firth
On Friday, September 4, 2015 at 4:51:43 AM UTC-7, Juan Francisco Cantero 
Hurtado wrote:
> On 09/03/2015 08:07 AM, Jack Firth wrote:
> > I've attempted to compile from source in an alpine image, but with no 
> > success. There's a bit too much arcane magic there for me to figure out how 
> > to do that.
> >
> 
> Can you show the errors on Alpine? Are you using Alpine in a container 
> or in a virtual/real machine?.
> 
> Alpine is interesting because they use grsecurity and musl.

I've got my attempt in the repo now under the 6.2-min folder. Furthest I've 
gotten - install dev tools including C compiler, download source, run 
./configure && make && make install, and watch errors show up.

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


Re: [racket-users] Macro-generating macros

2015-09-04 Thread Konrad Hinsen
Alexander D. Knauth writes:

 > > At least it's one that works. It feels like cheating to use dynamic
 > > scoping to get around a problem with lexical scoping, but knowing when
 > > to cheat is a fundamental competence when dealing with any bureaucracy ;-)
 > 
 > Um, the reason a syntax parameter is better is that it *does*
 > follow the lexical scoping rules, where the unhygienic version does
 > weird things you wouldn't expect. Using datum->syntax is cheating a
 > lot more, and syntax parameters deal with problems like this in a
 > much better way.

I agree that datum->syntax is cheating a lot more, no question.

Still, I just used it, and I don't feel bad about it because it makes
my code a lot more readable. I had gotten to the point of having a
macro introduce generated identifiers as syntax parameters for use by
another macro generated by the first macro as well.

Actually, I felt exactly like when I have to fight a type system: I
know my solution is OK, but the compiler cannot prove it and therefore
rejects it. In those cases I feel entitled to cheat as much as
necessary.

 > P.S.  Have you read Fear of Macros? If you haven't, I highly
 > recommend it because it's awesome.

It is. I had read it a year ago, and now re-read it. I'll probably have
to read it again in the future, but it *is* awesome :-)

Konrad.

-- 
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: help on coding finite state automata

2015-09-04 Thread mrmyers . random . suffix
On Friday, September 4, 2015 at 9:31:36 AM UTC-4, Michael Myers wrote:
> You might want to take a look at https://github.com/mromyers/automata
> specifically, https://github.com/mromyers/automata/blob/master/examples.rkt
> and https://github.com/mromyers/automata/blob/master/machines.rkt
> 
> I more or less just use the definition that was in my textbook: you provide 
> a transition function, and the DFA or NFA just uses stream-fold to get the 
> extended transition. I used a bunch of generics stuff to try to generalize
> everything past the point of practicality, but it's still reasonably
> fast.
> 
> It's not documented, but use (in-machine? M seq) to check for acceptance,
> (extended-transition M start seq) for final state(s).
> 
> There's also a minimization function and nfa->dfa conversion in there, but
> they're a bit fragile, so use at your own risk.

Sorry for the duplicate, this was sent yesterday, and only arived just now.

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


Re: [racket-users] Macro-generating macros

2015-09-04 Thread William Cushing
Racket's syntax-expander deliberately goes out of its way to break exactly
this example.  ("hygiene")

The issue/bug/ambiguity it is protecting you from is:
  (let ((send (lambda args (length args)) ))
(def (foo3 x y)
   (send x + y)
 ))
  (foo3 2 3) ;; In lisps with poor grooming, 5.  In racket, 3.  3 is not
what you wanted this time, but it is the better default behavior overall.


There are many ways to get exactly the desired syntactic behavior; syntax
parameters work, as does datum->syntax.


If you're willing to bend a little, a more racket-y solution, it seems to
me, is to force the user of the syntax to give you a name, like:
  (define-syntax-rule (with-SVO-as name body ...) (let-syntax ((name
(syntax-rules [(_ s v o ...) (v s o ...)] ))) body ...)

Which can be used like:
  (define (foo4 x y) (with-SVO-as send (send x + y)))

Or like:
  (define-syntax send (with-SVO-as n n))
  (define (foo5 x y) (send x + y))

Or like:
  (define (foo6 x y) (define-syntax send (with-SVO-as n n)) (send x + y))


That approach doesn't work so well for things like:
  (with-slots  (x y z) (person-x person-y person-z) the-person
(sqrt (* x x) (* y y) (* z z)))

That is, when there are lots of names to be bound, and they're pretty much
always the same, then the repetition/renaming at each use-site gets quite
tiresome; that is the problem that modules solve.

-Will


On Thu, Sep 3, 2015 at 9:59 AM, Brian Mastenbrook 
wrote:

> On Sep 3, 2015, at 11:44, Konrad Hinsen 
> wrote:
>
> > Hi everyone,
> >
> > Here's another plea for help from the macro experts. I am trying to
> > write a macro whose expansion contains another macro, more precisely a
> > let-syntax form. My full example is attached below. In the first part,
> > I use a let-syntax directly. In the second part, I use a macro that
> > generates exactly the form that I wrote by hand in the first part -
> > but then the let-syntax seems to be ignored.
> >
> > The macro stepper isn't of much help here. It shows the expansion
> > of (defn (foo2 ...)) into essentially what I wrote by hand for foo1,
> > and then declares the expansion finished.
> >
> > Can anyone tell me (1) why this doesn't work and (2) how to fix it?
>
> It's a capture problem. In the first case, you're just binding the name
> "send" locally and all is well. In the second case, you're trying to
> introduce a binding for "send" that you didn't get from the input form.
> You're also getting a confusing error because "send" is already bound; try
> using a name that's not already defined and you should get an unbound
> identifier.
>
> You can fix this in one of two ways. Your `def' macro could take the name
> of the `send' macro it binds as a parameter, which gets a little ugly.
> Alternatively, you can use a syntax parameter, which is probably the ideal
> solution here.
>
> (require (for-syntax syntax/parse))
> (require racket/stxparam)
>
> (define-syntax-parameter send (lambda (stx) (raise-syntax-error 'send
> "send used out of context")))
>
> (define-syntax (def stx)
>  (syntax-parse stx
>[(_ (fn-name:id arg:id ...) body ... )
> #'(define (fn-name arg ...)
> (syntax-parameterize ([send (λ (stx)
>   (syntax-parse stx
> [(send obj:expr method:id x:expr
> (... ...))
>  #'(method obj x (... ...))]))])
>  body ...))]))
>
> (def (foo2 x y)
>  (send x + y))
>
> (foo2 2 3)
>
>
> --
> Brian Mastenbrook
> br...@mastenbrook.net
> http://brian.mastenbrook.net/
>
> --
> 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] Re: help on coding finite state automata

2015-09-04 Thread Michael Myers
You might want to take a look at https://github.com/mromyers/automata
specifically, https://github.com/mromyers/automata/blob/master/examples.rkt
and https://github.com/mromyers/automata/blob/master/machines.rkt

I more or less just use the definition that was in my textbook: you provide 
a transition function, and the DFA or NFA just uses stream-fold to get the 
extended transition. I used a bunch of generics stuff to try to generalize
everything past the point of practicality, but it's still reasonably
fast.

It's not documented, but use (in-machine? M seq) to check for acceptance,
(extended-transition M start seq) for final state(s).

There's also a minimization function and nfa->dfa conversion in there, but
they're a bit fragile, so use at your own risk.


-- 
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: Official Docker images for Racket

2015-09-04 Thread Juan Francisco Cantero Hurtado

On 09/03/2015 08:07 AM, Jack Firth wrote:

I've attempted to compile from source in an alpine image, but with no success. 
There's a bit too much arcane magic there for me to figure out how to do that.



Can you show the errors on Alpine? Are you using Alpine in a container 
or in a virtual/real machine?.


Alpine is interesting because they use grsecurity and musl.

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


Re: [racket-users] Macro-generating macros

2015-09-04 Thread Alexander D. Knauth

> On Sep 4, 2015, at 4:26 AM, Konrad Hinsen  wrote:
> 
> Brian Mastenbrook writes:
> 
>> It's a capture problem. In the first case, you're just binding the
>> name "send" locally and all is well. In the second case, you're
>> trying to introduce a binding for "send" that you didn't get from
>> the input form.
> 
> Ahhh that one has bitten me before, but I had forgotten about it.
> Thanks for the reminder!
> 
>> You're also getting a confusing error because "send" is already
>> bound; try using a name that's not already defined and you should
>> get an unbound identifier.
> 
> I used a bound symbol intentionally to see if I can shadow an existing
> syntax transformer binding.

Ok, if you *really* want to shadow an existing binding, you can use 
datum->syntax, but using a syntax parameter is much better:
(define-syntax (def stx)
  (syntax-parse stx
[(_ (fn-name:id arg:id ...) body ... )
 #:with send-id (datum->syntax #'fn-name 'send)
 #'(define (fn-name arg ...)
 (let-syntax ([send-id (λ (stx)
 (syntax-parse stx
   [(send-id obj:expr method:id x:expr (... 
...))
#'(method obj x (... ...))]))])
   body ...))]))

>> Alternatively, you can use a syntax parameter, which is probably
>> the ideal solution here.
> 
> At least it's one that works. It feels like cheating to use dynamic
> scoping to get around a problem with lexical scoping, but knowing when
> to cheat is a fundamental competence when dealing with any bureaucracy ;-)

Um, the reason a syntax parameter is better is that it *does* follow the 
lexical scoping rules, where the unhygienic version does weird things you 
wouldn't expect. Using datum->syntax is cheating a lot more, and syntax 
parameters deal with problems like this in a much better way.

P.S.
Have you read Fear of Macros? If you haven't, I highly recommend it because 
it's awesome.

> Thanks again,
>  Konrad.

-- 
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] Issues with `head-pure-port'

2015-09-04 Thread Jay McCarthy
On Fri, Sep 4, 2015 at 3:05 AM, Tim Brown  wrote:
> Folks,
>
> I have just tried to HEAD a web server, and have come across a few
> issues around the use of head-pure-port:
>
> 1. What is the point of `head-pure-port'? The HTTP server should not
>(must not?) send a body. Which means that once the port is purified,
>`head-pure-port' returns nothing. So it was a bit silly of me to
>expect anything in the first place (this is before I bumped into
>connection persistence); maybe the documentation could ask the
>potential user, "Didn't you really want to use `head-impure-port'?"
>
> [So, in fact, I have issues with `head-impure-port']:
>
> 2. (port->string (head-impure-port
>   (string->url "http://www.bbc.co.uk/";)))
>takes way too long to potentially preflight a website.
>cpu time: 2578 real time: 29767 gc time: 125. This is due to
>HTTP keep-alive. For anyone who hits this, may I suggest two
>solutions:
> - keep-alive can be overridden with '("Connection: Close")
>   passed as a header in `head-impure-port'
>   (port->string (head-impure-port
>  (string->url "http://www.bbc.co.uk/";)
>  '("Connection: Close")))
>
> - if connection persistence is desirable (which I guess it usually
>   is), then read the header until an empty line:
>   (for/list ((p (in-port (curryr read-line 'return-linefeed)
>  (head-impure-port
>   (string->url "http://www.bbc.co.uk/";
>  #:break (string=? p ""))
>p)
>
> 3. Poking around url.rkt, I notice that `http-conn-impure-port' makes
>a pipe with a limit of 4096 bytes. http-client.rkt, which is directly
>required by url.rkt, defines (but does not provide) `PIPE-SIZE' --
>also 4096. Is there any merit in sharing this value between the
>files?

The reason is that the HTTP connecting part of url.rkt is a legacy
module. Now, whether it could also do what you suggest... maybe.

Jay

> Tim
>
> --
> Tim Brown  ▪ +447771714159
>
> --
> 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
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&C 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] help on coding finite state automata

2015-09-04 Thread Nguyen Linh Chi
Dear mrmyers, I cloned your repo however it's true that i complete have no
idea about macro yet. It'd be nice for further reading as i'd work on this
problem for long.

As soegaard suggests on IRC, to avoid the problem of creating new machines
after every interaction, i'd try to make the struct #:mutable. Hope that'd
be good.

Thanks for great advice,
Chi

On 4 September 2015 at 12:00, Jens Axel Søgaard 
wrote:

> Hi Linh,
>
> There are many different representations of finite state machines.
>
> If you "just" need to simulate a single machine, a simple and efficient
> approach is to represent each state as a Racket function (see example
> below).
>
> #lang racket
> (require racket/generator)
>
> ;; The turn-stile example from Wikipedia.
> ;;
> https://en.wikipedia.org/wiki/Finite-state_machine#Example:_coin-operated_turnstile
>
> ;; Current State  Input   Next State   Output
> ;;   LOCKED   coinUNLOCKED unlock turnstile so customer can
> push through
> ;;   LOCKED   push  LOCKED none (custome can't move through)
> ;; UNLOCKED   coinUNLOCKED none
> ;; UNLOCKED   push  LOCKED when customer is through, lock
> turnstile
>
> (define inputs '(coin push push push coin coin push))
> (define get-input (sequence->generator inputs))
>
> (define (LOCKED)
>   (match (get-input)
> ['coin(displayln "turnstile is unlocked")
>   (UNLOCKED)]
> ['push(displayln "you can't move through locked turnstile")
>   (LOCKED)]
> [_(DONE)]))
>
> (define (UNLOCKED)
>   (match (get-input)
> ['coin(displayln "no need to pay when the turnstile is unlocked")
>   (UNLOCKED)]
> ['push(displayln "customer goes through, turnstile is locked")
>   (LOCKED)]
> [_(DONE)]))
>
> (define (DONE)
>   (displayln "no more inputs"))
>
> (LOCKED) ; start turnstile in a locked state
>
>
>
>
> 2015-09-03 16:29 GMT+02:00 Linh Chi Nguyen :
>
>> Dear All,
>> I'm a complete newbie in racket and need help in coding finite state
>> machine/automata. Please pardon any of my ignorance.
>>
>> Thanks to this post of Tim Thornton, I see a very good way to code FSM:
>> http://timthornton.net/blog/id/538fa6f2f09a16ba0674813d
>>
>> I'd summarise it as following:
>> A finite state automaton has a number of states and each state has a name
>> plus many transition rules. He structures it in racket as following:
>>
>> (struct automaton (current-state states))
>> (struct state (name actions))
>> (struct action (event result))
>>
>> A simple automaton can be like this:
>> (define simple-fsm (fsm 'A
>> (list (fstate 'A (list (action 0 'A)
>>(action 1 'B)))
>>   (fstate 'B (list (action 0 'B)
>>(action 1 'A))
>>
>> The automaton is in state A which has 2 transition rules:
>> - if event 1 happens, the automaton jumps to state B,
>> - if event 0 happens, it stays in state A.
>>
>> Then he writes some functions to update the automaton after each event
>> (in the post). Plus this function he omits (I guess):
>> (define fsm-update-state old-fsm new-state)
>>   (struct-copy automaton old-fsm [current-state new-state]))
>>
>> HERE IS THE QUESTION:
>>
>> Using this way, after each event, there'd be a NEW automaton created. So
>> I'm worried about scaling. I'd like to generate 100 automata. In each
>> cycle, I'd pair the automata to interact for 50 times. Which means that
>> there'd be 100 new automata created for every single cycle. And I'd like to
>> run at least 1000 cycles.
>>
>> Would there be any problem with scaling? If yes, is there a way around
>> this?
>>
>> Any kind of comments and suggestions are welcomed and appreciated,
>> Thank you really much,
>> Chi
>>
>> --
>> 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
>
>


-- 
*Nguyen Linh Chi*

-- 
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] help on coding finite state automata

2015-09-04 Thread Jens Axel Søgaard
Hi Linh,

There are many different representations of finite state machines.

If you "just" need to simulate a single machine, a simple and efficient
approach is to represent each state as a Racket function (see example
below).

#lang racket
(require racket/generator)

;; The turn-stile example from Wikipedia.
;;
https://en.wikipedia.org/wiki/Finite-state_machine#Example:_coin-operated_turnstile

;; Current State  Input   Next State   Output
;;   LOCKED   coinUNLOCKED unlock turnstile so customer can
push through
;;   LOCKED   push  LOCKED none (custome can't move through)
;; UNLOCKED   coinUNLOCKED none
;; UNLOCKED   push  LOCKED when customer is through, lock
turnstile

(define inputs '(coin push push push coin coin push))
(define get-input (sequence->generator inputs))

(define (LOCKED)
  (match (get-input)
['coin(displayln "turnstile is unlocked")
  (UNLOCKED)]
['push(displayln "you can't move through locked turnstile")
  (LOCKED)]
[_(DONE)]))

(define (UNLOCKED)
  (match (get-input)
['coin(displayln "no need to pay when the turnstile is unlocked")
  (UNLOCKED)]
['push(displayln "customer goes through, turnstile is locked")
  (LOCKED)]
[_(DONE)]))

(define (DONE)
  (displayln "no more inputs"))

(LOCKED) ; start turnstile in a locked state




2015-09-03 16:29 GMT+02:00 Linh Chi Nguyen :

> Dear All,
> I'm a complete newbie in racket and need help in coding finite state
> machine/automata. Please pardon any of my ignorance.
>
> Thanks to this post of Tim Thornton, I see a very good way to code FSM:
> http://timthornton.net/blog/id/538fa6f2f09a16ba0674813d
>
> I'd summarise it as following:
> A finite state automaton has a number of states and each state has a name
> plus many transition rules. He structures it in racket as following:
>
> (struct automaton (current-state states))
> (struct state (name actions))
> (struct action (event result))
>
> A simple automaton can be like this:
> (define simple-fsm (fsm 'A
> (list (fstate 'A (list (action 0 'A)
>(action 1 'B)))
>   (fstate 'B (list (action 0 'B)
>(action 1 'A))
>
> The automaton is in state A which has 2 transition rules:
> - if event 1 happens, the automaton jumps to state B,
> - if event 0 happens, it stays in state A.
>
> Then he writes some functions to update the automaton after each event (in
> the post). Plus this function he omits (I guess):
> (define fsm-update-state old-fsm new-state)
>   (struct-copy automaton old-fsm [current-state new-state]))
>
> HERE IS THE QUESTION:
>
> Using this way, after each event, there'd be a NEW automaton created. So
> I'm worried about scaling. I'd like to generate 100 automata. In each
> cycle, I'd pair the automata to interact for 50 times. Which means that
> there'd be 100 new automata created for every single cycle. And I'd like to
> run at least 1000 cycles.
>
> Would there be any problem with scaling? If yes, is there a way around
> this?
>
> Any kind of comments and suggestions are welcomed and appreciated,
> Thank you really much,
> Chi
>
> --
> 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] Macro-generating macros

2015-09-04 Thread Konrad Hinsen
Brian Mastenbrook writes:

 > It's a capture problem. In the first case, you're just binding the
 > name "send" locally and all is well. In the second case, you're
 > trying to introduce a binding for "send" that you didn't get from
 > the input form.

Ahhh that one has bitten me before, but I had forgotten about it.
Thanks for the reminder!

 > You're also getting a confusing error because "send" is already
 > bound; try using a name that's not already defined and you should
 > get an unbound identifier.

I used a bound symbol intentionally to see if I can shadow an existing
syntax transformer binding.

 > Alternatively, you can use a syntax parameter, which is probably
 > the ideal solution here.

At least it's one that works. It feels like cheating to use dynamic
scoping to get around a problem with lexical scoping, but knowing when
to cheat is a fundamental competence when dealing with any bureaucracy ;-)

Thanks again,
  Konrad.

-- 
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] Issues with `head-pure-port'

2015-09-04 Thread Tim Brown
Folks,

I have just tried to HEAD a web server, and have come across a few
issues around the use of head-pure-port:

1. What is the point of `head-pure-port'? The HTTP server should not
   (must not?) send a body. Which means that once the port is purified,
   `head-pure-port' returns nothing. So it was a bit silly of me to
   expect anything in the first place (this is before I bumped into
   connection persistence); maybe the documentation could ask the
   potential user, "Didn't you really want to use `head-impure-port'?"

[So, in fact, I have issues with `head-impure-port']:

2. (port->string (head-impure-port
  (string->url "http://www.bbc.co.uk/";)))
   takes way too long to potentially preflight a website.
   cpu time: 2578 real time: 29767 gc time: 125. This is due to
   HTTP keep-alive. For anyone who hits this, may I suggest two
   solutions:
- keep-alive can be overridden with '("Connection: Close")
  passed as a header in `head-impure-port'
  (port->string (head-impure-port
 (string->url "http://www.bbc.co.uk/";)
 '("Connection: Close")))

- if connection persistence is desirable (which I guess it usually
  is), then read the header until an empty line:
  (for/list ((p (in-port (curryr read-line 'return-linefeed)
 (head-impure-port
  (string->url "http://www.bbc.co.uk/";
 #:break (string=? p ""))
   p)

3. Poking around url.rkt, I notice that `http-conn-impure-port' makes
   a pipe with a limit of 4096 bytes. http-client.rkt, which is directly
   required by url.rkt, defines (but does not provide) `PIPE-SIZE' --
   also 4096. Is there any merit in sharing this value between the
   files?

Tim

-- 
Tim Brown  ▪ +447771714159

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