Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Scheme eval issues
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?


Report this thread to moderator Post Follow-up to this message
Old Post
grocery_stocker
03-22-08 03:18 AM


Re: Scheme eval issues
In article
<ee8a286a-3aaf-4966-9307-4ef0778c8725@s8g2000prg.googlegroups.com>,
grocery_stocker <cdalten@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?

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, barmar@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***

Report this thread to moderator Post Follow-up to this message
Old Post
Barry Margolin
03-22-08 03:18 AM


Re: Scheme eval issues
On Mar 21, 7:13=A0pm, Barry Margolin <bar...@alum.mit.edu> wrote:
> In article
> <ee8a286a-3aaf-4966-9307-4ef0778c8...@s8g2000prg.googlegroups.com>,
>
>
>
>
>
> =A0grocery_stocker <cdal...@gmail.com> wrote: 
> 
> 
> 
> 
> 
>
> Take a look at the documentation of the eval procedure. =A0How many
> arguments does it require?
>

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) =3D> Return to read-eval-print level 1.

Report this thread to moderator Post Follow-up to this message
Old Post
grocery_stocker
03-22-08 03:18 AM


Re: Scheme eval issues
In article
<c6204e9e-dbeb-45d8-90c9-1aed64e14d41@e10g2000prf.googlegroups.com>,
grocery_stocker <cdalten@gmail.com> wrote:

> On Mar 21, 7:13_pm, Barry Margolin <bar...@alum.mit.edu> wrote: 
>
> I haven't found the internal documentation for the eval procedure yet.

Here's the R5RS documentation:

http://www.schemers.org/Documents/S...-Z-H-9.html#%_i
dx_578


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

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***

Report this thread to moderator Post Follow-up to this message
Old Post
Barry Margolin
03-22-08 03:18 AM


Re: Scheme eval issues
From: Matt Birkholz <matt@birkholz.chandler.az.us>
Message-ID: <87iqz3xr9j.fsf@birkholz.chandler.az.us>
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)
Cancel-Lock: sha1:gNmFKDtc1AibqhVNj89qYvUa+ko=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Lines: 93
NNTP-Posting-Host: 68.14.216.67
X-Complaints-To: newsmaster@cox.net
X-Trace: newsfe12.phx 1206950081 68.14.216.67 (Mon, 31 Mar 2008 00:54:41 MST
)
NNTP-Posting-Date: Mon, 31 Mar 2008 00:54:41 MST
Organization: Cox
Date: Mon, 31 Mar 2008 00:54:32 -0700
Bytes: 4538
Xref: number1.nntp.dca.giganews.com comp.lang.scheme:73580 comp.lang.scheme.
c:3104

Barry Margolin <barmar@alum.mit.edu> writes:

> In article
> <c6204e9e-dbeb-45d8-90c9-1aed64e14d41@e10g2000prf.googlegroups.com>,
>  grocery_stocker <cdalten@gmail.com> wrote:
> 
 

A highly optimized Scheme implementation doesn't tell you the name of
the procedure that was called.  Generally, a Scheme procedure has no
name.
 
>
> 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.

Report this thread to moderator Post Follow-up to this message
Old Post

03-31-08 11:15 AM


Re: Scheme eval issues
Matt Birkholz wrote:
 
> 
>
> 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,,,

Report this thread to moderator Post Follow-up to this message
Old Post
Abdulaziz Ghuloum
03-31-08 11:16 AM


Re: Scheme eval issues
Abdulaziz Ghuloum wrote:

> 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

Report this thread to moderator Post Follow-up to this message
Old Post
Jens Axel Soegaard
04-01-08 03:19 AM


Re: Scheme eval issues
Abdulaziz Ghuloum <aghuloum@cee.ess.indiana.edu> writes:

> Matt Birkholz wrote:
> 

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

Report this thread to moderator Post Follow-up to this message
Old Post
Matt Birkholz
04-01-08 03:19 AM


Re: Scheme eval issues
Matt Birkholz wrote:

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

Report this thread to moderator Post Follow-up to this message
Old Post
Taylor R. Campbell
04-01-08 03:20 AM


Re: Scheme eval issues
"Taylor R. Campbell" <riastradh@gmail.com> writes:

> Matt Birkholz wrote:
> 
>
> 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!

Report this thread to moderator Post Follow-up to this message
Old Post
Matt Birkholz
04-01-08 03:20 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Scheme archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:13 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.