Re: [racket-users] Case and eof

2016-04-06 Thread Jay McCarthy
You would want (== eof), because 'eof' is just an identifier, so
you're binding x to eof.

Jay

On Wed, Apr 6, 2016 at 12:05 PM, rom cgb  wrote:
> On Monday, April 4, 2016 at 10:44:46 PM UTC+2, Alex Knauth wrote:
>> 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.
>
> How to use eof with match ?
>
> For example, with
>
> (define (test x)
> (match x [1   "one"]
>  [2   "two"]
>  [eof "eof"]
>  [3   "three"]))
>
> Why (test 3) evaluates to "eof", not "three" ?
>



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

2016-04-06 Thread rom cgb
On Monday, April 4, 2016 at 10:44:46 PM UTC+2, Alex Knauth wrote:
> 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.

How to use eof with match ?

For example, with

(define (test x) 
(match x [1   "one"] 
 [2   "two"] 
 [eof "eof"] 
 [3   "three"]))

Why (test 3) evaluates to "eof", not "three" ?

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


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