(define (rep-loop)
(display "repl>")
(write (eval (read)))
(rep-loop))
1 ]=> (rep-loop)
repl>(+ 4 5)
When I run this, or any kind of variation, I an error message that is
something like the following.
"The procedure has been called with 1 argument; it requires exactly
two arguments.
Ideas?
Take a look at the documentation of the eval procedure. How many
arguments does it require?
What Scheme implementation are you using that doesn't tell you the name
of the procedure that was called with the wrong number of arguments?
--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***
I haven't found the internal documentation for the eval procedure yet.
> What Scheme implementation are you using that doesn't tell you the name
> of the procedure that was called with the wrong number of arguments?
>
The MIT/GNU Scheme doesn't appear to have some kind of cut and paste
option.
Here is the entire error message
;The procedure #[compiled-procedure 11 ("global" #x7) #xf #xaf8753]
has been called with 1 argument; it requires exactly 2 arguments.
;To continue, call RESTART with the option number:
; (RESTART 1) => Return to read-eval-print level 1.
> On Mar 21, 7:13 pm, Barry Margolin <bar...@alum.mit.edu> wrote:
> > In article
> > <ee8a286a-3aaf-4966-9307-4ef0778c8...@s8g2000prg.googlegroups.com>,
> >
> >
> >
> >
> >
> > grocery_stocker <cdal...@gmail.com> wrote:
> > > This SHOULDN'T matter, but the following questions stems from running
> > > Scheme under Windows XP.
> >
> > > (define (rep-loop)
> > > (display "repl>")
> > > (write (eval (read)))
> > > (rep-loop))
> >
> > > 1 ]=> (rep-loop)
> > > repl>(+ 4 5)
> >
> > > When I run this, or any kind of variation, I an error message that is
> > > something like the following.
> >
> > > "The procedure has been called with 1 argument; it requires exactly
> > > two arguments.
> >
> > > Ideas?
> >
> > Take a look at the documentation of the eval procedure. How many
> > arguments does it require?
> >
>
> I haven't found the internal documentation for the eval procedure yet.
Here's the R5RS documentation:
http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-9.html#%_i
dx_578
>
> > What Scheme implementation are you using that doesn't tell you the name
> > of the procedure that was called with the wrong number of arguments?
> >
>
> The MIT/GNU Scheme doesn't appear to have some kind of cut and paste
> option.
>
> Here is the entire error message
>
> ;The procedure #[compiled-procedure 11 ("global" #x7) #xf #xaf8753]
> has been called with 1 argument; it requires exactly 2 arguments.
> ;To continue, call RESTART with the option number:
> ; (RESTART 1) => Return to read-eval-print level 1.
Well, that's not very helpful. I wonder why it can't say "The procedure
eval has been called with 1 argument...".
> In article
> <c6204e9e-dbeb-45d8...@e10g2000prf.googlegroups.com>,
> grocery_stocker <cda...@gmail.com> wrote:
>
>> On Mar 21, 7:13 pm, Barry Margolin <bar...@alum.mit.edu> wrote:
>> > What Scheme implementation are you using that doesn't tell you the name
>> > of the procedure that was called with the wrong number of arguments?
A highly optimized Scheme implementation doesn't tell you the name of
the procedure that was called. Generally, a Scheme procedure has no
name.
>> Here is the entire error message
>>
>> ;The procedure #[compiled-procedure 11 ("global" #x7) #xf #xaf8753]
>> has been called with 1 argument; it requires exactly 2 arguments.
>> ;To continue, call RESTART with the option number:
>> ; (RESTART 1) => Return to read-eval-print level 1.
>
> Well, that's not very helpful. I wonder why it can't say "The procedure
> eval has been called with 1 argument...".
Many procedures have no name, or many names. By the time the
interpreter has detected the wrong-number-of-arguments situation, the
name has been "reduced" to a procedure object. You need the debugger.
Enter "(debug)", then hit the "b" key to move "Backward" in the
Execution History. You should find an expression and environment has
been recorded.
Now using information from the execution history.
Subproblem level: 0 Reduction number: 0
Expression (from execution history):
(eval (read))
Environment created by the procedure: REP-LOOP
applied to: ()
Hopefully you will guess that if #@11 got 1 argument and wanted
2, and the history says the interpreter just reduced (eval (read))
then #@11 might be 'eval in REP-LOOP's environment -- the (user)
environment. To verify, evaluate
(access eval (procedure-environment rep-loop))
or
(access eval (->environment '(user)))
You should get good ol' #@11.
Value 11: #[compiled-procedure 11 ("global" #x7) #xf #x2722db]
NOTE that this is difficult because Scheme procedures do not have
names, and COMPILED Scheme procedures REALLY do not have names. If
you were abusing an interpreted procedure defined with the "define"
syntax, you would see a named-lambda, e.g.
Value 11: #[compound-procedure 11 eval]
BUT these names are just debugging aids. There may be many procedures
named 'eval'. Here is a procedure that creates bunches.
1 ]=> (define (curried-eval env)
(define (eval exp)
(extended-scode-eval (syntax exp env) env))
eval)
Value: curried-eval
1 ]=> (curried-eval (->environment '(user)))
Value 23: #[compound-procedure 23 eval]
1 ]=> (curried-eval (->environment '(runtime)))
Value 24: #[compound-procedure 24 eval]
1 ]=> (curried-eval (->environment '(cross-reference)))
Value 25: #[compound-procedure 25 eval]
So many procedures; so few names!
I am afraid niceties like "named-lambdas" and records for the
Execution History are compiled away. An unfortunate side-effect of
this is that getting freaky with the compiled runtime system can leave
you with few clues -- few "names". If the debugger cannot turn up any
hints, I get busy with the printfs, or load interpreted versions of
the troublesome parts of the runtime system.
>>> On Mar 21, 7:13 pm, Barry Margolin <bar...@alum.mit.edu> wrote:
>
>>>> What Scheme implementation are you using that doesn't tell you the name
>>>> of the procedure that was called with the wrong number of arguments?
>
> A highly optimized Scheme implementation doesn't tell you the name of
> the procedure that was called. Generally, a Scheme procedure has no
> name.
First, optimizations are besides the point (see below). Second, yes,
not all Scheme procedures have names, but many do. The issue was about
eval which is a system procedure. So, what Scheme implementations don't
know the names of its own procedures? And which ones don't know the
names of local (say let-bound) procedure?
Let's test it (by typing an input expression at the repl):
INPUT: eval
chez #<procedure eval>
ikarus #<procedure eval>
mzscheme #<procedure:eval>
gosh #<subr eval>
scheme48 #{Procedure 5115 (eval in evaluation)}
chicken #<procedure (eval x648 . env649)>
larceny #<PROCEDURE eval>
petite #<procedure eval>
gambit #<procedure #2 eval>
mit-scheme #[compiled-procedure 1 ("global" #x7) #xf #x2720ab]
bigloo #<procedure:422099.-1>
INPUT: (let ((f (lambda (x) (+ x 12)))) f)
chez #<procedure f>
ikarus #<procedure f>
mzscheme #<procedure:f>
gosh #<closure f>
scheme48 #{Procedure 8508 f}
chicken #<procedure (f x)>
larceny #<PROCEDURE>
petite #<procedure>
gambit #<procedure #2>
mit-scheme #[compound-procedure 1]
bigloo #<procedure:436432.1>
Summary: eval f extra junk?
chez C yes yes no
ikarus C yes yes no
mzscheme C yes yes no
gosh I yes yes no
scheme48 I yes yes maybe
chicken I yes yes maybe
larceny C yes no no
petite I yes no no
gambit I yes no maybe
mit-scheme C no no maybe
bigloo I no no maybe
[C=compiler (native), I=interpreter (not native)]
> NOTE that this is difficult because Scheme procedures do not have
> names, and COMPILED Scheme procedures REALLY do not have names.
This may be true for one or two systems. Fortunately, in most systems,
compiled procedures do have useful names.
Aziz,,,
> Let's test it (by typing an input expression at the repl):
> INPUT: (let ((f (lambda (x) (+ x 12)))) f)
It's also interesting to look at the result when
we apply the result to the wrong number of arguments.
How many implementations remember where f was defined? (*)
Welcome to MzScheme v3.99.0.12 [3m]
> ((let ((f (lambda (x) (+ x 12)))) f) 1 2)
procedure f: expects 1 argument, given 2: 1 2
=== context ===
/Applications/PLT Scheme v3.99.0.12/collects/scheme/private/misc.ss:63:7
(*) In the hope you used a script to generate the examples.
--
Jens Axel Søgaard
> Matt Birkholz wrote:
>
>>>> On Mar 21, 7:13 pm, Barry Margolin <bar...@alum.mit.edu> wrote:
>>
>>>>> What Scheme implementation are you using that doesn't tell you the name
>>>>> of the procedure that was called with the wrong number of arguments?
>>
>> A highly optimized Scheme implementation doesn't tell you the name of
>> the procedure that was called. Generally, a Scheme procedure has no
>> name.
Sorry; I did not mean to suggest that YOUR Scheme is not highly
optimized(?). I just wanted to help the MIT-Scheme user who is stuck
trying to find the code that applied a procedure.
> Second, yes, not all Scheme procedures have names, but many do. The
> issue was about eval which is a system procedure. So, what Scheme
> implementations don't know the names of its own procedures? And
> which ones don't know the names of local (say let-bound) procedure?
The MIT/GNU Scheme system does not "own" eval. It is treated
(compiled) like any other procedure. You will need the debugging
tools I demonstrated sooner or later. I understand that "sooner"
sucks.
>> NOTE that this is difficult because Scheme procedures do not have
>> names, and COMPILED Scheme procedures REALLY do not have names.
>
> This may be true for one or two systems. Fortunately, in most
> systems, compiled procedures do have useful names.
Actually, 6/11 of the systems you surveyed did not provide a
useful name for (lambda (x) (+ x 12)).
If I was crazy, trying to debug compiled code like
(map (lambda () 1) '(a b c))
and expecting a "useful name" for the procedure that is mis-applied, I
might think I was completely lost. As a sympathetic MIT-Scheme luser,
I was trying to get the other luser un-lost. What are you trying to
do?
I believe I was replying to a Common Lisp guru who wondered aloud why
this is not simple. My answer was:
* This is Scheme after all.
* Compiled-code optimizations have tossed the info you
were hoping for.
* MIT-Scheme provides debugging tools that can help with
this problem especially in the non-trivial, even
already-compiled cases.
One easily overlooked debugging tool is MIT-Scheme's pretty-printer
and its "unhash" read syntax. (OK, if you insist, I am begging for a
survey of similar facilities in a dozen other implementations, else I
am trying to insinuate that no other Scheme has them.)
In the case of an apply error in compiled code like
(map (lambda () ...) ...)
I get this message: The procedure #[compiled-procedure 15 ("t"
#x2) #x2d #xd90821] has been called with 1 argument; it
requires exactly 0 arguments.
Believe it or not, that error message is not entirely unhelpful.
Consider
2 error> (pp #@15)
(lambda ()
1)
;Unspecified return value
The printed representation of #@15, "(lambda () 1)", is NOT the
original source code, luser preferences notwithstanding. It is
actually the s-code -- a disassembly of the compiled byte-code. In
less trivial situations (e.g. code containing macros), such a
disassembly may not look much like the code that needs fixing.
> I am afraid niceties like "named-lambdas" and records for the
> Execution History are compiled away. An unfortunate side-effect of
> this is that getting freaky with the compiled runtime system can leave
> you with few clues -- few "names". If the debugger cannot turn up any
> hints, I get busy with the printfs, or load interpreted versions of
> the troublesome parts of the runtime system.
This has nothing whatsoever to do with interpretation versus
compilation, or optimization, or anything of the sort. There is
no name presented because MIT Scheme by default does not load the
debugging information necessary to present the name. One can
force the debugging information to be loaded, for instance by
pretty-printing the procedure, or one can request that MIT Scheme
load it by setting the variable LOAD-DEBUGGING-INFO-ON-DEMAND? to
true. One might put
(SET! LOAD-DEBUGGING-INFO-ON-DEMAND? #T)
in one's ~/.scheme.init file (or whatever the analogue of it is on
Windows) to enable this always.
> Matt Birkholz wrote:
>
>> I am afraid niceties like "named-lambdas" and records for the
>> Execution History are compiled away. [...]
>
> This has nothing whatsoever to do with interpretation versus
> compilation, or optimization, or anything of the sort. There is
> no name presented because MIT Scheme by default does not load the
> debugging information necessary to present the name.
Whether LOAD-DEBUGGING-INFO-ON-DEMAND? is an optimization or not, it
is good to hear we can get the names back. The flag is even
documented (in the Compilation Procedures node of the User Manual).
Thanks!
> === context ===
> /Applications/PLT Scheme v3.99.0.12/collects/scheme/private/misc.ss:63:7
That is cool. Line.. AND column numbers? File.line.column can
reference unnamed and ambiguously named procedure text unambiguously!
How does that work with macros? I heard a rumor on the street (Scheme
St.) that someone did a thesis (long ago?) about mapping from machine
state back to source code (file.line.col?) THROUGH (simple?) macro
transforms. If that thesis exists, is it available on the web?
Could you elaborate the question?
--
Jens Axel Søgaard
> Matt Birkholz skrev:
>> Jens Axel Soegaard <inv...@soegaard.net> writes:
>>
>>> === context ===
>>> /Applications/PLT Scheme v3.99.0.12/collects/scheme/private/misc.ss:63:7
>>
>> That is cool. Line.. AND column numbers? File.line.column can
>> reference unnamed and ambiguously named procedure text unambiguously!
>>
>> How does that work with macros?
>
> Could you elaborate the question?
If I evaluate this special form
(dotimes (i 'a) (display i) (newline))
and it expands to
(let ((bounds 'a))
(let loop ((i 0))
(if (fix:< i bounds)
(begin
(display i) (newline)
(loop (fix:1+ i))))))
I would expect a runtime error message like
;The object a, passed as the second argument to fix:<, is not the
;correct type.
but what source code location would be referenced, and how -- under
what conditions?
A 90% solution that was published 15 years ago would be a patent-
defensible boon. It would be cool if some of the Scheme work from 20
years ago gradually appeared on The Net (i.e. with few copy rights
withheld), so that it can be easily found and referenced as prior art.