Discussion:
[Larceny-users] recursive lists and C-c problems
Marco Maggi
2008-12-07 20:15:51 UTC
Permalink
Ciao,

I am new to Larceny (10 minutes) taking a look at
larceny-0.963-bin-native-ia32-linux86) and I see
that this script goes into an endless loop:

(import (rnrs)
(rnrs mutable-pairs (6)))

(write (let ((v '(1 #f)))
(set-car! (cdr v) v)
v))
(newline)

when run with "scheme-script". Ikarus and the last
Ypsilon do not, so I wonder why Larceny chooses to
fill my terminal with "(1" until I hit Control-c. :)

After hitting C-c, I see that the debugger is here
and I can exit it with "q". And I am left with a prompt?
Does it mean that I am forbidden to create a set[ug]id
script with Larceny?
--
Marco Maggi

"Now feel the funk blast!"
Rage Against the Machine - "Calm like a bomb"
William D Clinger
2008-12-08 15:53:13 UTC
Permalink
Post by Marco Maggi
I am new to Larceny (10 minutes) taking a look at
larceny-0.963-bin-native-ia32-linux86)
v0.97b1 is newer and should have fewer bugs.
Post by Marco Maggi
and I see
(import (rnrs)
(rnrs mutable-pairs (6)))
(write (let ((v '(1 #f)))
(set-car! (cdr v) v)
v))
(newline)
when run with "scheme-script". Ikarus and the last
Ypsilon do not, so I wonder why Larceny chooses to
fill my terminal with "(1" until I hit Control-c. :)
The R6RS does not specify any finite notation for
circular pseudo-lists, and the R6RS also forbids
extensions to its syntax that could express circular
pseudo-lists.

Attempts to print circular pseudo-lists in R6RS-conforming
systems should result in infinite output. Ikarus and
Ypsilon, like Larceny, may default to a non-conforming
mode in which they have extended the R6RS notations,
contrary to the R6RS's explicit language concerning
extensions; if so, then Ikarus and Ypsilon should
provide some kind of switch that will force them into
a conforming mode, at least with regard to lexical
and datum syntax. In Larceny, the #!r6rs flag serves
that purpose; you might try that in Ikarus and Ypsilon.
Post by Marco Maggi
After hitting C-c, I see that the debugger is here
and I can exit it with "q". And I am left with a prompt?
Yes. It isn't a very useful prompt, since nothing is
in scope, but it's a prompt.
Post by Marco Maggi
Does it mean that I am forbidden to create a set[ug]id
script with Larceny?
I think that's up to your operating system. Larceny
is normally executed via a shell script, and the OS
(for security) may ignore the set[ug]id attribute of
shell scripts.

Control-C is not the only security problem that should
concern you. Although Larceny checks for accidental
problems with the R6RS top-level program and libraries
being executed, it does not even try to guard against
malicious manipulation of the program and libraries.

Will
Marco Maggi
2008-12-08 20:33:29 UTC
Permalink
Post by Marco Maggi
I am new to Larceny (10 minutes) taking a look at
larceny-0.963-bin-native-ia32-linux86)
v0.97b1 is newer and should have fewer bugs.
Is it also still open to very small non-language
related changes?
The R6RS does not specify any finite notation for
circular pseudo-lists [...] Attempts to print
circular pseudo-lists in R6RS-conforming
systems should result in infinite output.
Fine. But is there a switch that makes larceny print
some non-infinite output in
R6RS-compatible-mode-for-everything-else?
Post by Marco Maggi
After hitting C-c, I see that the debugger is here
and I can exit it with "q". And I am left with a prompt?
Yes. It isn't a very useful prompt, since nothing is
in scope, but it's a prompt.
Nothing is in scope until I issue "(import (rnrs))",
then I do what I want with escalated privileges.
Although Larceny checks for accidental
problems with the R6RS top-level program and libraries
being executed, it does not even try to guard against
malicious manipulation of the program and libraries.
It would suffice to have a command line switch that
makes the process exit whenever an exception is not
blocked.
--
Marco Maggi

"Now feel the funk blast!"
Rage Against the Machine - "Calm like a bomb"
David Rush
2008-12-08 21:06:02 UTC
Permalink
Post by Marco Maggi
Post by William D Clinger
Post by Marco Maggi
After hitting C-c, I see that the debugger is here
and I can exit it with "q". And I am left with a prompt?
Yes. It isn't a very useful prompt, since nothing is
in scope, but it's a prompt.
Nothing is in scope until I issue "(import (rnrs))",
then I do what I want with escalated privileges.
As I said earlier, if you're running setuid, you should have
*thoroughly* debugged your code. Then you will not hit the prompt.
Post by Marco Maggi
It would suffice to have a command line switch that
makes the process exit whenever an exception is not
blocked.
How about installing your own error-handler that just exits the
program? There's a really simple API for this. You could minimally
just use the code:

(error-handler (lambda _ (exit)))

and get your result. Which is not very helpful because is you haven't
debugged sufficiently that you are still getting errors which
terminate the program, you generally would like to know what went
wrong. Hence the following code (which is part of my Larceny standard
prelude):

(require 'inspect-cont)
(define (batch/last-chance-handler puts)
(lambda e
(define (display-line s)
(puts (with-output-to-string
(lambda() (write s)))))

(display-line `(lastchance error handler ,e))

(let* ((error-text
(call-with-output-string (lambda (p) (decode-error e p))))
(stacktrace (current-continuation-structure))
(inspector (make-continuation-inspector stacktrace))

(summarize-frame
(lambda (count inspector . prefix)
(let* ((frame (inspector 'get))
(code (frame 'code))
(class (code 'class))
(expr (code 'expression))
(proc (code 'procedure)))
(display-line
`(frame ,@prefix ,class
,@(case class
((system-procedure) '())
((interpreted-primitive) (procedure-name proc))
((interpreted-expression) expr)
((compiled-procedure) (procedure-name proc))
(else '())))
))))

(backtrace
(lambda (count inspector)
(let loop ((c (inspector 'clone)))
(let ((f (c 'get)))
(if (f 'same? (inspector 'get))
(summarize-frame 0 c "=> ")
(summarize-frame 0 c " ")))
(if (c 'down)
(loop c))
)))
)
(display-line `(decoded error ,error-text))
(backtrace 0 inspector)
(exit 0)
)))

(define (install-lastchance puts)
(error-handler (batch/last-chance-handler puts))

To use this fragment, call:

(install-lastchance puts-function)

where puts-function takes a string and does something appropriate with it.

david
--
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt
Ray Racine
2008-12-08 22:41:24 UTC
Permalink
http://github.com/GreyLensman/rl3/tree/webserver/rl3/env/debug.sls

Here is another example of establishing your own error handler in ERR5RS
(R6RS kinda sorta) Larceny.
I had it bound to my emacs. When debug was "disabled" the handler prints
the error and leaves you at the top level REPL and not in the debugger. Its
just a simple example. Dave's solution actually give a solution for your
specific concern.

There is some other Larceny ERR5RS sorta/kinda R6RS code there as well.
Unfortunately its not system agnostic and a clean build with
compile-stale-libraries requires a Linux box. Its mostely web oriented.
HTTP, continuation threading, sockets support that works with the R6RS I/O,
SXML, Amazon Cloud client code, a small REST web server, etc...
Unfortunately its not well documented and a bit of mess. I hope to get back
to it early next year.

Ray
Post by David Rush
Post by Marco Maggi
Post by William D Clinger
Post by Marco Maggi
After hitting C-c, I see that the debugger is here
and I can exit it with "q". And I am left with a prompt?
Yes. It isn't a very useful prompt, since nothing is
in scope, but it's a prompt.
Nothing is in scope until I issue "(import (rnrs))",
then I do what I want with escalated privileges.
As I said earlier, if you're running setuid, you should have
*thoroughly* debugged your code. Then you will not hit the prompt.
Post by Marco Maggi
It would suffice to have a command line switch that
makes the process exit whenever an exception is not
blocked.
How about installing your own error-handler that just exits the
program? There's a really simple API for this. You could minimally
(error-handler (lambda _ (exit)))
and get your result. Which is not very helpful because is you haven't
debugged sufficiently that you are still getting errors which
terminate the program, you generally would like to know what went
wrong. Hence the following code (which is part of my Larceny standard
(require 'inspect-cont)
(define (batch/last-chance-handler puts)
(lambda e
(define (display-line s)
(puts (with-output-to-string
(lambda() (write s)))))
(display-line `(lastchance error handler ,e))
(let* ((error-text
(call-with-output-string (lambda (p) (decode-error e p))))
(stacktrace (current-continuation-structure))
(inspector (make-continuation-inspector stacktrace))
(summarize-frame
(lambda (count inspector . prefix)
(let* ((frame (inspector 'get))
(code (frame 'code))
(class (code 'class))
(expr (code 'expression))
(proc (code 'procedure)))
(display-line
((system-procedure) '())
((interpreted-primitive) (procedure-name proc))
((interpreted-expression) expr)
((compiled-procedure) (procedure-name proc))
(else '())))
))))
(backtrace
(lambda (count inspector)
(let loop ((c (inspector 'clone)))
(let ((f (c 'get)))
(if (f 'same? (inspector 'get))
(summarize-frame 0 c "=> ")
(summarize-frame 0 c " ")))
(if (c 'down)
(loop c))
)))
)
(display-line `(decoded error ,error-text))
(backtrace 0 inspector)
(exit 0)
)))
(define (install-lastchance puts)
(error-handler (batch/last-chance-handler puts))
(install-lastchance puts-function)
where puts-function takes a string and does something appropriate with it.
david
--
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt
_______________________________________________
Larceny-users mailing list
https://lists.ccs.neu.edu/bin/listinfo/larceny-users
William D Clinger
2008-12-09 03:42:10 UTC
Permalink
Post by Marco Maggi
v0.97b1 is newer and should have fewer bugs.
Is it also still open to very small non-language
related changes?
Yes.
Post by Marco Maggi
Fine. But is there a switch that makes larceny print
some non-infinite output in
R6RS-compatible-mode-for-everything-else?
No, but there should be. I'm waiting to see what
happens with SRFI 38 and SRFI 97.
Post by Marco Maggi
It would suffice to have a command line switch that
makes the process exit whenever an exception is not
blocked.
For what purpose(s) would that suffice? If by
"exception" you mean an R6RS exception, then it
seems to me you could do that yourself by installing
a handler. Furthermore that seems like the only
portable way to do it; you can't count on all
implementations of the R6RS having exactly the
same set of random extensions to the language.

Will
David Van Horn
2008-12-09 19:55:22 UTC
Permalink
Post by William D Clinger
Post by Marco Maggi
v0.97b1 is newer and should have fewer bugs.
Is it also still open to very small non-language
related changes?
Yes.
Post by Marco Maggi
Fine. But is there a switch that makes larceny print
some non-infinite output in
R6RS-compatible-mode-for-everything-else?
No, but there should be. I'm waiting to see what
happens with SRFI 38 and SRFI 97.
SRFI 97 should be final by the end of the week. SRFI 37 was one of the
omitted SRFIs from that proposal, so what exactly are waiting to see
about, or what would you like to see happen with SRFI 97 in regard to
SRFI 37?

Thanks,
David
David Van Horn
2008-12-09 19:58:52 UTC
Permalink
Post by David Van Horn
Post by William D Clinger
No, but there should be. I'm waiting to see what
happens with SRFI 38 and SRFI 97.
SRFI 97 should be final by the end of the week. SRFI 37 was one of the
omitted SRFIs from that proposal, so what exactly are waiting to see
about, or what would you like to see happen with SRFI 97 in regard to
SRFI 37?
Sorry -- I read 37 instead of 38, which is included and should be
available under the name `with-shared-structure' in SRFI 97. Are you
just waiting for SRFI 97 to go final?

David
Marco Maggi
2008-12-09 07:22:48 UTC
Permalink
Post by William D Clinger
Post by Marco Maggi
It would suffice to have a command
line switch that makes the process
exit whenever an exception is not
blocked.
For what purpose(s) would that suffice?
If by "exception" you mean an R6RS
exception, then it seems to me you could
do that yourself by installing a handler.
I used bad words. What I mean is that I am
UNused to runtimes that enter a debugger
by default when running a program; my
least surprise behaviour is to just exit
with an error code, when something that
the program was not expecting goes wrong.
IMHO the go-in-debugger-by-default is a
REPL thing.

I see this as both a security problem and
a workflow problem.

I speculate that most of the times I would
just exit the debugger because I am not
"ready" for a debug session (I rarely use
the debugger in any language). For example,
when I am in a write-and-run cycle for a test
suite using the lightweight testing SRFI, and
I make a mistake that causes an exception to
go through to the top level (not a failing
test, but a mistake in using something), I do
not want to enter the debugger: I just want
to see the error message.

It may be that I have a bad workflow...
--
Marco Maggi

"Now feel the funk blast!"
Rage Against the Machine - "Calm like a bomb"
David Rush
2008-12-09 11:17:59 UTC
Permalink
Post by Marco Maggi
It may be that I have a bad workflow...
Not bad, so much as one that is not traditional in the Lisp community.

david
--
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt
William D Clinger
2008-12-09 20:15:34 UTC
Permalink
Are you just waiting for SRFI 97 to go final?
I have also been waiting for the end of the semester
so I'd have time to work on v0.97 again. With the
end of the semester upon us, I'm just waiting to see
whether there will be any further changes to SRFI 97
before I start to implement the libraries it proposes.

I don't expect to implement all of those legacy SRFIs
for v0.97, but I do expect to implement SRFI 38 because
we have had multiple requests for it, and because I can
easily produce a completely portable version of it from
my reference implementation of get-datum [1].

Will

[1] http://www.ccs.neu.edu/home/will/R6RS/

Loading...