[racket-users] Re: [racket] Sorry, but what's the correct way to use `#lang scribble/lp2`

2016-01-11 Thread WarGrey Gyoudmon Ju
Oh, yes, perhaps I did not understand Symbols well, especially in TEXT MODE.
I don't remember how did I find the solution.

Nonetheless, thank you all the same.

On Tue, Jan 12, 2016 at 2:42 AM, Ismael Figueroa 
wrote:

> Maybe it is too late for this, but I run into the same issue just now...
>
> In my case I get the same error when using:
>
> @include-section["path.rkt"]
>
> but it works when using
>
> @include-section[(submod "path.rkt" doc)]
>
> probably because the scribble/lp2 is not providing the doc submodule
> expected by scribble itself...
>
> Cheers
>
>
>
> 2015-02-21 11:22 GMT-02:00 WarGrey Gyoudmon Ju :
>
>> Glad to see the literate programming technology updated.
>> I thought it might be a "Forgotten Feature" since the rest of scribble is
>> so powerful and I cannot find any code base use it.
>> Thank you.
>>
>> So... there still should be more examples to work with it.
>> What's the extra work (rather than simply replacing scribble/lp with
>> scribble/lp2) has to be done to make it able to be `include-section`ed?
>>
>> `scribble path.rkt`
>> `raco scribble path.rkt`
>> `(include-section (submod "path.rkt" doc))`
>> All of these complain:
>> path-only: contract violation
>>   expected: (or/c path-string? path-for-some-system?)
>>   given: #f
>>
>> and `(include-section "path.rkt")` complains:
>> handbook.scrbl:71:18: only-in: identifier `doc' not included in nested
>> require spec at: "path.rkt" in: (only-in "makefile.rkt" (doc doc))
>>
>>
>> 
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
>>
>>
>
>
> --
> Ismael
>

-- 
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] Web server: can't get radio-group formlet to process

2016-01-11 Thread Jay McCarthy
Hi Marc,

Most formlets are typed as `(formlet/c (or/c false/c binding?))` where
the `binding?` is returned when the thing is there and the `#f` is
returned when it isn't. However, if you use `required`, then an
exception is thrown on the `#f` because the form element must be
present. Formlets like `input-string` include a call to `required`. I
think that you either want to handle the `#f` or use `default` to have
a default value present. Similarly most formlets like `text-input`
have an optional `#:value` keyword for starting them off with a value.

I think a better form DSL could be built out of formlets that
automatically did client & server-side checking with looping
re-submission until correct, etc. But that's not what formlets are yet
and you have to roll it yourself.

Jay


On Sun, Jan 10, 2016 at 9:05 PM, Marc Kaufmann
 wrote:
> Thanks.
>
> Another question about formlets: when I use (formlet-process formlet-name)
> it will often raise errors when a field doesn't have a value. Is there an
> easy way of capturing errors, in particular to show the form as it was
> entered by the user, but with an error message at the top, rather than
> blowing up?
>
> One way I can imagine doing this is to catch the errors via (with-handlers
> ... ), and then resend the form with previous answers pre-populated. So, I
> would do the following, where 'answer' is the string ("Yes" or "No") that
> was associated with the checked answer previously.
>
> (define (rg-formlet answer)
>   (define (was-answer? a)
> (equal? a answer))
>   (formlet
> (label
>   ,{(radio-group '("Yes" "No") #:checked was-answer?) . => . answer})
> answer))
>
> Is this the way to do it, or is there an easier way (since forms with
> missing elements can't be such a rarity - and yes, I'll do checking on the
> client-side as well).
>
> Thanks,
> Marc
>
> On Sun, Jan 10, 2016 at 5:08 PM, Jay McCarthy 
> wrote:
>>
>> On Sun, Jan 10, 2016 at 3:50 PM, Marc Kaufmann
>>  wrote:
>> > Hi,
>> >
>> > I manage to get the basic formlets to work, and tried the radiogroup,
>> > but it
>> > fails with the following error: "input-group: invalid selection #f",
>> > even
>> > though I had it selected. After some playing around, I saw that there
>> > are
>> > two input_0 fields being sent on submit, since I have another formlet on
>> > the
>> > same page (with a separate formlet-display and formlet-process).
>> >
>> > My question is: If I use formlets, do I have to put all the formlets
>> > into
>> > one big formlet on every page, as otherwise fields will have the same
>> > name
>> > attribute, and there will be clashes?
>>
>> Each form can have only one formlet. There can be different forms on a
>> page, I believe.
>>
>> Jay
>>
>> > Thanks,
>> > Marc
>> >
>> >
>> > --
>> > 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
>
>



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


[racket-users] Re: [racket] Sorry, but what's the correct way to use `#lang scribble/lp2`

2016-01-11 Thread Ismael Figueroa
Maybe it is too late for this, but I run into the same issue just now...

In my case I get the same error when using:

@include-section["path.rkt"]

but it works when using

@include-section[(submod "path.rkt" doc)]

probably because the scribble/lp2 is not providing the doc submodule
expected by scribble itself...

Cheers



2015-02-21 11:22 GMT-02:00 WarGrey Gyoudmon Ju :

> Glad to see the literate programming technology updated.
> I thought it might be a "Forgotten Feature" since the rest of scribble is
> so powerful and I cannot find any code base use it.
> Thank you.
>
> So... there still should be more examples to work with it.
> What's the extra work (rather than simply replacing scribble/lp with
> scribble/lp2) has to be done to make it able to be `include-section`ed?
>
> `scribble path.rkt`
> `raco scribble path.rkt`
> `(include-section (submod "path.rkt" doc))`
> All of these complain:
> path-only: contract violation
>   expected: (or/c path-string? path-for-some-system?)
>   given: #f
>
> and `(include-section "path.rkt")` complains:
> handbook.scrbl:71:18: only-in: identifier `doc' not included in nested
> require spec at: "path.rkt" in: (only-in "makefile.rkt" (doc doc))
>
>
> 
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
>


-- 
Ismael

-- 
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: Code critique request: data/fetch, proc for walking hashes/lists

2016-01-11 Thread Jack Firth
I'd probably prefer using a fold over explicit recursion. This gets easier if 
you split your code into two steps - one that does just one level of lookup, 
and one that does nested lookups. Additionally, I'd prefer list indexes rather 
than pair lookup functions:

(define (data/ref s key)
  (cond
[(hash? s) (hash-ref s key)]
[(list? s) (list-ref s key)]
[else fail-somehow ...]))

(define (data/fetch s keys)
  (define (fetch-once key s)
(data/ref s key))
  (foldl fetch-once s keys))


> (data/ref (hash 'a 1 'b 2) 'a)
1
> (data/ref '(a b c) 2)
'c
> (data/fetch (hash 'a '(foo bar baz) 'b 0) '(a 2))
'baz

By splitting the recursion (define (data/ref s key)
  (cond
[(hash? s) (hash-ref s key)]
[(list? s) (list-ref s key)]
[else fail-somehow ...]))

(define (data/fetch s keys)
  (define (fetch-once key s)
(data/ref s key))
  (foldl fetch-once s keys))


> (data/ref (hash 'a 1 'b 2) 'a)
1
> (data/ref '(a b c) 2)
'c
> (data/fetch (hash 'a '(foo bar baz) 'b 0) '(a 2))
'baz

-- 
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: Code critique request: data/fetch, proc for walking hashes/lists

2016-01-11 Thread Jack Firth
I'd probably prefer using a fold over explicit recursion. This gets easier if 
you split your code into two steps - one that does just one level of lookup, 
and one that does nested lookups. Additionally, I'd prefer list indexes rather 
than pair lookup functions:

(define (data/ref s key)
  (cond
[(hash? s) (hash-ref s key)]
[(list? s) (list-ref s key)]
[else fail-somehow ...]))

(define (data/fetch s keys)
  (define (fetch-once key s)
(data/ref s key))
  (foldl fetch-once s keys))


> (data/ref (hash 'a 1 'b 2) 'a)
1
> (data/ref '(a b c) 2)
'c
> (data/fetch (hash 'a '(foo bar baz) 'b 0) '(a 2))
'baz

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