How to record scheme session in a file? - scheme

I'm trying to record my session while writing some scheme code, But I don't know which is the correct code to record my session while doing some expression.

R5RS
R5RS has an optional procedure transcript-on that takes a file name and it will output the interaction until transcript-off` is called. (Thanks #molbdnilo for pointing this out in a comment)
R6RS and R7RS
This is not supported in the report. Even (scheme-report-environment 5)‌ is specified not to contain the optional procedures load, interaction-environment, transcript-on, transcript-off, and char-ready?.
Implementation lock-ins
The individual implementations might have such features included and if you just need it for you chosen implementation you must read its documentation to find it. I guess this is for tooling rather than production code so using implementation specific features isn't as bad as using non scheme standard forms.
roll your own
You can make your own repl that does what you want with the file output of you chosing that would be the same across all implementations.

Related

Can R7RS-small implementations allow only one define-library per file?

Are compliant R7RS-small implementations allowed to impose a restriction on the number of define-library per file? Some R7RS-small implementations such as Guile 3.0.7 only allow one define-library per file. Is this a deviation from the standard, or is it allowed by R7RS-small?
In R7RS define-library is just a form, similar to library in R6RS. I don't see any allowances in either case that conforming implementations may constrain a file to contain only one such form.
But the Guile documentation has something to say on the matter. In 7.7 R7RS Support:
Happily, the syntax for R7RS modules was chosen to be compatible with R6RS, and so Guile’s documentation there applies.
In 7.7.1 Incompatibilities with the R7RS:
As the R7RS is a much less ambitious standard than the R6RS (see Guile and Scheme), it is very easy for Guile to support. As such, Guile is a fully conforming implementation of R7RS, with the exception of the occasional bug and a couple of unimplemented features....
Then in 7.6.1 Incompatibilities with the R6RS
Multiple library forms in one file are not yet supported. This is because the expansion of library sets the current module, but does not restore it. This is a bug.
Yes, I think they can (and, perhaps, should).
If you look at the formal syntax & semantics in r7rs.pdf then
A program is one or more import declarations followed by one or more commands or definitions. Commands and definitions don't include define-library.
A library is exactly one define-library form.
So from that you can conclude that a program doesn't include define-library forms, and a library includes exactly one such form.
Now that document doesn't say how all this maps into files at all, so it's up to the implementation to define that. I think it would be perfectly possible for an implementation to say that the mapping of files to library files should be 1-1, so any given library file contains exactly one library. It would also be possible to have files which contained mixtures of a program and one or more libraries, of course.
In the case where libraries are in their own files (which is obviously the more interesting case in terms of allowing reuse) something has to turn a library name into a file. And that would make it reasonably natural to put exactly one library in each file.
If it was me, I'd allow files which contain a mixture of a program and one or more libraries directly present, but for files which were just libraries I'd allow just one in each file.

How to get all bindings visible in current scope in Scheme48 (or any Scheme for that matter)

I'm doing some stuff with Scheme48/Scsh. What I find rather inconvenient is the lack of name completion (analogous to Guile's (ice-9 readline) or Racket's Xrepl). But before Scheme48 gets completion (if it ever does) I'd like to be able to do some introspection by hand. My question is how can you get the list of all identifiers defined/visible in the current context. If I understand correctly, Scheme has one unified namespace for variables and functions (unlike Common Lisp), so this would supply information about both. Any suggestions will be appreciated.
You want to introspect environments. I am not sure that Scheme 48 has such a feature, but its module system is perhaps the way to do it.
You might want the (interaction-environment) of R7RS. I guess that S48 is not R7RS compliant.

Scheme - standard way in R5RS to execute an external command?

Is there a way in Scheme Revision 5 to call out to an external program? For example:
(system "ls")
If not, is there any "official" way to do this, such as specified in a SRFI or a later revision of the Scheme spec (R6RS, etc)?
No.
(It's generally a bad idea to try to write code with "Standard Scheme", and system is one of those things that is unlikely to become standard enough to be usable outside of a particular implementation or via some compatibility library.)

Implementation details of scheme library procedures?

As per my understanding scheme procedures like map,apply,append etc are written in scheme itself. Is there an easy way to see the implementation of these procedues right inside the REPL ?
I do not believe there is a standard way to dump the source code of a procedure, but a lot of the list functions are defined here, and you can look through the source code for your implementation to see the rest. Note that apply is probably a primitive, though.

How can lisp (scheme) be compiled to binary file?

I am using a softerware who has a build-in scheme interpreter. Users can communicate / manipulate the software by typing command in the interpreter. And users also could load some binary file to the environment. I have write some scheme code like this:
(define test (lambda() (display "This is a test!"))) ---- d:/test.scm
And then compile it into binary file which will be loaded and excuted much faster. But the document has no information about compilation of the scheme code.
After compilation user could load the binary file by typing:
(fast-load "d:/test.bin" (the-environment))
I think the "fast-load" just do read and eval things. So does the compilation is just a encrypting process? Does anybody know about these things? Any information will be appreciated! Thanks in advance.
And there is another example: the AutoCAD system. Users can write lisp code to manipulate the AutoCAD. And user could compile the lisp code into *.fas file which will be loaded into AutoCAD. So if it is really only an encrypting process, how can I write a compiler? Is there any documents about it?
Joe
If you are strictly talking about the application's built-in interpreter (as seems to be the case based on your question), there's no standard answer. You'll need to see if the application designer built compilation into their implementation and exposed that functionality for you. If not you're out of luck.
If you were to ask about stand-alone Scheme applications or libraries, many implementations (such as Chicken) provide Scheme compilers of one sort or another (the previously-mentioned Chicken Scheme compiles to C first).
If you were asking about Common Lisp (ignoring the fact that you mention Scheme specifically in your title and question). You can use the standard function, compile-file, which produces the .fasl format you alluded to at the end of your question.

Resources