jscl icon indicating copy to clipboard operation
jscl copied to clipboard

to implement load function

Open t-cool opened this issue 7 years ago • 8 comments

@davazp Hi, David.

I'm raising some budget at the Bountysource account t-cool, and I'll spend some of the budget on developing JSCL.

I asked cxxxr to implement load function on JSCL. He'll implement it in a week or so. Could you tell me how to implement load function if you have the specific way? If you don't, I'll ask him to implement it as he wants.

By the way, I started developing jscl-playground as an experiment to make a frontend app using JSCL. At first, I implemented LOGO turtle to play on it.
https://t-cool.github.io/jscl-playground

Regards.

  • Noguchi

t-cool avatar Feb 08 '18 05:02 t-cool

Nice playground!

load requires file system right? So I propose to implement it only on node.js for now. The implementation can be easy in there, some FFI magic to read the file content little by little and calling the compiler on each toplevel form.

The concerns here are, load is synchronous, it will wait until the file is totally loaded. If we want to have that, then it should use fs.readFileSync. But of course that will block the event loop.

The alternative would be for load to return asynchronously, but then it would not be compatible with the CL spec.

I think 2) is not acceptable, but I get this async/sync mixed feeling all the time and it is a big limitation of JSCL right now. It would be nice to have a better solution without going full CPS.

Anyway, I hope it helps, and thanks!

davazp avatar Feb 08 '18 07:02 davazp

load accepts a stream or a pathname designator.

HTML5 sort of has a file system. <input type=file> creates a button which opens dialog on the client and returns a list of File objects. You can then use FileReader or FileReaderSync

if load accepted a stream, you could use with-input-from-string and FileReader.readAsText()

aarvid avatar Feb 08 '18 13:02 aarvid

load is still not implemented in node.js. fs.readFileSync should be used in my opinion. It may block the event loop, but the return value could be needed (success or error for example), plus, even if it blocks the event loop, then load is most of the time called on initialization.

hlolli avatar Sep 22 '18 04:09 hlolli

Good point @hlolli. I'm reopening the ticket. load on nodejs should be relatively simple.

davazp avatar Sep 22 '18 07:09 davazp

A url based load was added in #337. I would like to rename that to load-url and use sync node version for load.

davazp avatar Nov 23 '18 06:11 davazp

Maybe add another key to the load? something like :sync?

(load "./app.lisp"   :sync t)  ; sync/ from local fs
(load  "https://dark.net/pro/app.lisp") ;  async/ from www or local fs

The file reader here will be simple. and the compilation function is already there. Work here for a couple of hours.

vlad-km avatar Nov 23 '18 07:11 vlad-km

I would find strange that the :sync t version doesn't work with URLs. If it is an key, I would expect the file/url argument to behave the same regardless the sync value. But if we can make that, then sure! Although sync should default to t probably for CL compatibility.

davazp avatar Nov 23 '18 07:11 davazp

In my opinion, the main thing here is that the compilation of a large number of expressions, completely blocks all other processes. This is both in synchronous reading and asynchronous.

I'll see what can be done and offer a new version.

If there are other implementations, that's good. We will have a choice.

vlad-km avatar Nov 23 '18 07:11 vlad-km