Re: [racket] else: not allowed as an expression in: else

2010-12-21 Thread Jon Rafkind
On 12/21/2010 05:29 PM, Danny Yoo wrote:
> On Tue, Dec 21, 2010 at 3:57 PM, Niitsuma Hirotaka
>  wrote:
>> I try to run this code on racket
>>
>> http://www.daniweb.com/forums/thread277930.html
>>
>> After little modify I enables run this code on swindle.
>> But when I chose language racket, this code cause error
>>
>> else: not allowed as an expression in: else
> The eopl/eopl module is providing its own version of the conditional
> form 'cond'.  The error you're seeing is because it is not cooperating
> with racket's else.
>
> One way to resolve this is to only use the eopl bindings for
> define-datatype and cases, which you can do like this:
>
>
> ;; Comment out the original require to eopl/eopl
> ;;
> ;; (require eopl/eopl)
> ;;
> ;; and replace it with this:
> ;;
> (require (only-in eopl/eopl
>   define-datatype
>   cases
>   eopl:error))
>
>
>
>
> However: is there a reason why the whole module isn't just written in
> #lang eopl?

Just using #lang eopl will result in this error (at least)

k.rkt:39:10: compile: unbound identifier in module in: andmap
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] else: not allowed as an expression in: else

2010-12-21 Thread Jon Rafkind
If you change from #lang racket to #lang mzscheme your program will work.

I'm pretty sure the issue is that eopl was defined in terms of the
'mzscheme' language where `cond' checks for `else' symbolically. The
`else' you are using is from the 'racket' language where its defined as
a syntactic transformer that cannot be used as an expression, it can
only be used inside `cond' forms from the 'racket' language.

Well maybe thats not 100% right, but its something like that. The whole
situation (combining the mzscheme and racket modules) pretty
unfortunate, IMO.

On 12/21/2010 04:57 PM, Niitsuma Hirotaka wrote:
> I try to run this code on racket
>
> http://www.daniweb.com/forums/thread277930.html
>
> After little modify I enables run this code on swindle.
> But when I chose language racket, this code cause error
>
> else: not allowed as an expression in: else
>
> flowing is the modified code
> ---
>
> #lang racket
>
> (require eopl/eopl)
>
> ;The helpers used in parse and unparse
>
> ;(define list-of
> ;  (lambda (pred)
> ;(lambda (val)
> ;  (or (null? val)
> ;   (and (pair? val)
> ;(pred (car val))
> ;((list-of pred) (cdr val)))
>
> ;combines 2 lists of the same size
> ;as a list of list with corresponding elements
> (define combine
>   (lambda (ls1 ls2)
> (if (null? ls1)
> '()
>   (append (list (list (car ls1) (car ls2)))
> (combine (cdr ls1) (cdr ls2))
>
>
> (define improperlist?
>   (lambda (x)
> (and (pair? x) (not (list? x)
>   
> (define literal?
>   (lambda (x)
> (or (number? x)
>   (string? x)
>   (boolean? x)
>   (vector? x
>
> (define list-of-lists?
>   (lambda (x)
> (and (list? x)
>(andmap list? x
>
> (define lengths-equal-two?
>   (lambda (x)
> (= (length x) 2)))
>
> (define firsts
>   (lambda (ls)
> (if (null? ls)
> '()
>   (cons (caar ls)
> (firsts (cdr ls))
>
> (define lasts
>   (lambda (ls)
> (if (null? ls)
> '()
>   (cons (cadar ls)
> (lasts (cdr ls))
>
>
>
>
> (define-datatype expression expression?
>   [var-exp
> (id symbol?)]
>   [lambda-exp
> (vars (list-of symbol?))
> (bodies (list-of expression?))]
>   [lambda-var-improp-exp
> (vars (list-of improperlist?))
> (bodies (list-of expression?))]
>   [lambda-var-sym-exp
> (vars symbol?)
> (bodies (list-of expression?))]
>   [set-exp
> (id symbol?)
> (var expression?)]
>   [app-exp
> (rands (list-of expression?))]
>   [lit-exp
> (id literal?)]
>   [if-exp
> (test expression?)
> (true expression?)
> (false expression?)]
>   [if-noelse-exp
> (test expression?)
> (true expression?)]
>   [let-exp
> (vars (list-of symbol?))
> (vals (list-of expression?))
> (bodies (list-of expression?))]
>   [let*-exp
> (vars (list-of symbol?))
> (vals (list-of expression?))
> (bodies (list-of expression?))]
>   [letrec-exp
> (vars (list-of symbol?))
> (vals (list-of expression?))
> (bodies (list-of expression?))]
>   [letname-exp
> (name symbol?)
> (vars (list-of symbol?))
> (vals (list-of expression?))
> (bodies (list-of expression?))])
>
>
>
>
>
> ;parse
> (define parse-exp
>   (lambda (datum)
> (cond
>   [(symbol? datum) (var-exp datum)]
>   [(literal? datum) (lit-exp datum)]
>   [(pair? datum)
>(cond
>[(eqv? (car datum) 'lambda)
> (if (< (length (cdr datum)) 2)
> (eopl:error 'parse-exp "Invalid lambda syntax ~s" datum)
> (cond
>   [(list? (cadr datum))
>(lambda-exp (cadr datum)
>(map parse-exp (cddr datum)))]
>   [(symbol? (cadr datum))
>(lambda-var-sym-exp (cadr datum)
>(map parse-exp (cddr datum)))]
>   [(improperlist? (cadr datum))
>(lambda-var-improp-exp (cadr datum)
>   (map parse-exp (cddr datum)))]
>   [else
> (eopl:error 'parse-exp
>   "Invalid lambda syntax ~s" datum)]))]
>[(eqv? (car datum) 'set!)
> (if (= (length (cdr datum)) 2)
> (set-exp (cadr datum)
>  (parse-exp (caddr datum)))
> (eopl:error 'parse-exp
>   "Invalid set! syntax ~s" datum))]   
>[(eqv? (car datum) 'set)
>   (eopl:error "Invalid set syntax ~s" datum)]
>[(eqv? (car datum) 'if)
> (cond
>   [(= (length (cdr datum)) 3)
>(if-exp (parse-exp (cadr datum))
>(parse-exp (caddr datum))
>(parse-exp (cadddr datum)))]
>   [(= (length (cdr datum)) 2)
>(if-noelse-exp (parse-exp (cadr datum))
>   (parse-exp (caddr datum)))]
>   [else
>

Re: [racket] else: not allowed as an expression in: else

2010-12-21 Thread Danny Yoo
On Tue, Dec 21, 2010 at 3:57 PM, Niitsuma Hirotaka
 wrote:
> I try to run this code on racket
>
> http://www.daniweb.com/forums/thread277930.html
>
> After little modify I enables run this code on swindle.
> But when I chose language racket, this code cause error
>
> else: not allowed as an expression in: else

The eopl/eopl module is providing its own version of the conditional
form 'cond'.  The error you're seeing is because it is not cooperating
with racket's else.

One way to resolve this is to only use the eopl bindings for
define-datatype and cases, which you can do like this:


;; Comment out the original require to eopl/eopl
;;
;; (require eopl/eopl)
;;
;; and replace it with this:
;;
(require (only-in eopl/eopl
  define-datatype
  cases
  eopl:error))




However: is there a reason why the whole module isn't just written in
#lang eopl?
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users