Home > Archive > Scheme > June 2007 > Re: Silly question - Why doesn't a non-procedure expr evaluate to
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Silly question - Why doesn't a non-procedure expr evaluate to
|
|
| Jens Axel Søgaard 2007-06-15, 7:13 pm |
| Adrian skrev:
> Please be kind - this may be a very dumb question.
>
> I was wondering why an expression that is not a procedure doesn't
> simply evaluate to itself in a procedure application? i.e., why don't
> all such expressions have an intrinsic procedure that returns the
> expression?
>
> Why can't (123) return 123?
It could. In which situations would it be practical?
--
Jens Axel Søgaard
| |
| Jens Axel Søgaard 2007-06-15, 7:13 pm |
| Adrian skrev:
>
> Wouldn't it increase the regularity of the language to remove the
> positional distinction between functions and data in a function
> application? I'm guessing there is some fundamental problem with that
> idea.
Can you give a concrete example, where it would be practical?
If you want to experiment with the idea, then try the
following in the "Pretty Big" language in DrScheme:
(module funny-app mzscheme
(provide (rename funny-app #%app))
(define-syntax (funny-app stx)
(syntax-case stx ()
[(_ expr1)
#'(let ([e1 expr1])
(if (procedure? e1)
(e1)
e1))]
[(_ expr1 expr ...)
#'(let ([e1 expr1])
(if (procedure? e1)
(e1 expr ...)
(error "non-procedure used in operator position")))])))
(require funny-app)
(+ 1 2) ; => 3
(+ (1) 2) ; => 3
(1) ; => 1
(0 1) ; => error : non-procedure ...
--
Jens Axel Søgaard
| |
|
|
|
|
|