How to load files in Scheme lisp - scheme

I've been trying to load another file into my Scheme scrip but when I do this,
(load "fn1.lisp")
the error came out as
The port #[input-port 13 for file: "/Users/yiwenzhu/Library/Mobile Documents/com~apple~CloudDocs/work/study/computer/SICP/src_lisp/fn1.lisp"] signalled an error:
The primitive channel-read, while executing the read system call, received the error: Bad address.
How to solve this? Thanks.

load is the only compatible way until R5RS, but after that the standard introduced libraries. Where the files need to be installed is implementation dependent, but the source structure on how to define and use isn't.
Also know that SICP is pre-R5RS so there isn't one modern Scheme implementation that would run the books examples without some compatibility layer. Eg. I have an answer about how to do SICP with DrRacket.
Since we don't know how the file you are trying to include look like or which Scheme implementation you are using I'm afraid I cannot help you further. I can update if you update your question.

Related

How can I use a Common Lisp (Clozure CL) Library?

I'm learning Common Lisp (Clozure CL) on the Mac and would like to create a simple GUI. I have downloaded the "ltk" library from CLiki and put it into the project directory at the root level (I assumed I had to do this as I couldn't find instructions for a beginner).
Page 4 of the "LTK - a Lisp binding to the Tk toolkit" documentation says that the library should be compiled using (compile-file "ltk") before loading the library using (load "ltk"). However, I get this error message:
Error: File #P"/Users/myName/Desktop/lisp_experiments/GUI_EXAMPLE/ltk" not found
While executing: CCL::FCOMP-FIND-FILE, in process Listener(4).
Type cmd-. to abort, cmd-\ for a list of available restarts.
Type :? for other options.
I also used the full file pathname and got the same error.
What am I doing wrong?
Thanks for your help.
Marc
ps - there are almost no noob tutorials about this sort of thing online that takes the user through the process step by step.
I have downloaded the "ltk" library from CLiki and put it into the project directory at the root level.
Nowadays, this is a step that is seldom required, because libraries are easily accessible using Quicklisp (see also this gif).
Basically, you should be able to install Quicklisp and run the following:
(ql:quickload "ltk")
The above downloads, compiles and install Lisp libraries, but not necessarily the required C libraries, which you might need to install separately. If the above works without problem, then the following should work too:
(ltk:ltktest)
Quicklisp relies on Lisp systems being described with ASDF (Another System Definition Facility). The best practices document is also interesting to read.
In the case of LTK, you can see that ltk.asd only specifies one component, ltk.lisp. When you install the system named "LTK", quicklisp will do all the necessary work to install its dependencies, then compile and load ltk.lisp, as described in the manual.
What is unclear is why your explicit compile-file failed.
I found the ltk.lisp file on my machine; its pathname looks like:
#P"/home/user/quicklisp/dists/quicklisp/software/ltk-20150113-http/ltk.lisp"
Sure enough, calling compile-file with that pathname works and returns another pathname which ends in .fasl (the object format). Loading the returned pathname loads the library. Please provide more information about the error so that we can help you debug this problem.

Library to read, generate or validate protocol buffer spec?

What's a smart way to generate and validate a protocol buffer spec? Is there any library (binding?) for the protoc file format, maybe java or python?
Just to be clear, I know that after my code generates a protocol buffer specification it will be fed to protoc for generating language-specific binding code. It's straightforward for me to invoke protoc to validate a generated spec (just check exit code etc.), but I thought maybe there's a better way.
The only vaguely related thing I could find is Cannot parse a protocol buffers file in python when using the correct .proto file
Thanks in advance.
I would probably just invoke the protoc binary and check the exit code, because that command line interface is likely to be more stable across versions than a library interface.
However, all the relevant functionality is available in libprotoc.so. As a starting point, you can see the protoc main program here, which is beautifully short: https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/main.cc
I expect you could pretty much copy that to your own project and link against libprotoc.so.

Ruby 'compile' while coding

Using Java big IDEs compile my code while it is written so that errors are detected before runtime.
Is that possible with Ruby too? Actually I code in a Text editor. Errors are detetected at runtime only.
Is that possible with Ruby too?
If by that you mean "compiling", then no. If you mean "edit-time error detection", then also no.
Smart IDEs, like RubyMine, can guess/detect some errors, but only simple cases. And they are often confused by ruby's dynamic nature. (can't find location for a method, even though it's defined within the project. Or the opposite, find too many false positives).
In ruby, you simply can't know what does a piece of code do without running it.

Is there an equivalent to HLint for Erlang?

HLint is a Haskell lint tool for making code more idiomatic. Is there something like it for Erlang?
There is a tool called "Tidier": http://tidier.softlab.ntua.gr/mediawiki/index.php/Main_Page, which is based on a simpler module called erl_tidy which is part of the syntax_tools library: http://www.erlang.org/doc/man/erl_tidy.html.
Tidier is used via a web interface, letting you choose interactively which changes you want it to perform. It can do some amazing things, and is a great tool for learning how to write idiomatic Erlang.
Yes there is. Its called erl_lint
There's now also elvis. Although it is not specifically a linter, it does check that Erlang code conforms to certain rules which can be configured.

In Ruby, what's the equivalent of Java's technique of limiting access to source in a cowork situation?

In Java when you compile a .java file which defines a class, it creates a .class file. If you provide these class files to your coworkers then they cannot modify your source. You can also bundle all of these class files into a jar file to package it up more neatly and distribute it as a single library.
Does Ruby have any features like these when you want to share your functionality with your coworkers but you don't want them to be able to modify the source (unless they ask you for the actual .rb source file and tell you that they want to change it)?
I believe the feature you are looking for is called "trust" (and a source code control repository). Ruby isn't compiled in the same way that Java is, so no you can't do this.
I have to say your are in a rough position, not wanting to share code with a coworker. However, given that this is an unassailable constraint perhaps you could change the nature of the problem.
If you have a coworker that needs access to some service provided by a library of yours, perhaps you could expose it by providing a web/rest service instead of as a .rb file.
This way you can hide your code behind a web server, and if there is a network architecture that allows for low latency making these service calls, you can effectively achive the same goal.
Trust is a lot easier though.
edit:
Just saw this on HN: http://blog.astrails.com/2009/5/12/ruby-http-require, allows a ruby file to include another file through http instead of the filesystem.
Ruby is
A dynamic, interpreted, open source programming language with a focus on simplicity and productivity.
So like all interpreted languages, you need to give the source code to anyone who want's to execute your program/script.
By the way searching "compiled ruby" on google returned quiet a few results.
I don't think there is one. Ruby is purely an interpreted language, which means ruby interprets your source code directly in order to run it. Java is compiled, so there's an intermediate bytecode (the .class). You can obfuscate your ruby if you really wish, but it's probably more trouble than it's worth.
Just to make sure you realize, however, upwards of 95% of Java can be decompiled back into source using various free utilities, so in reality, Java's compilation isn't much better than distributing Ruby source.
This is not a language specific problem and one that can be managed more effectively through source control software.
There is a library called ruby2c that compiles a subset of Ruby into C code (which you can then compile into native code, if you want).
It was actually originally written as a Ruby code obfuscator (but has since been used for lots of other stuff, including Ruby Arduino development).

Resources