LIPS-scheme / lips

Scheme based powerful lisp interpreter in JavaScript
https://lips.js.org
Other
412 stars 33 forks source link

require() usage #114

Closed ElonVolo closed 3 years ago

ElonVolo commented 3 years ago

I'm not sure if this is bug or my incomplete understanding how lips interacts with node modules.

First off, from what I'm understanding, lips currently supports? using require() directly from lisp. I tried looking through the few examples in the documentation to understand how to do this from lisp, but I think my understanding maybe incomplete.

So I was trying to use the fast-glob module from lisp to read the current directory.

Here's how it works in javascript:

const fg = require('fast-glob'); const entries = fg.sync('./**/*'); console.log(entries);

I run the above code where I use fast-glob's sync() function and I get a very long list of the files in my current directory.

I then run what I think is the equivalent in lips lisp:

(define fg (require "fast-glob")) (display (fg.sync "./**/*"))

And I get the below error. It's as if fast-globs sync() function doesn't exist. From looking at few examples in the node.js example, I thought that (module.function params) is the correct way to call a module's function in lips. Is there a different way I should be calling sync()? Any light you could shed on this would be greatly appreciated. :)

/Users/foobaz/Dev/lispthing/node_modules/@jcubic/lips/src/lips.js:2078 throw new Error("Unbound variable `" + name + "'"); ^

Error: Unbound variable `fg.sync' at Environment.get (/Users/foobaz/Dev/lispthing/node_modules/@jcubic/lips/src/lips.js:2078:19) at evaluate (/Users/foobaz/Dev/lispthing/node_modules/@jcubic/lips/src/lips.js:4187:29) at getFunctionArgs (/Users/foobaz/Dev/lispthing/node_modules/@jcubic/lips/src/lips.js:4115:27) at evaluate (/Users/foobaz/Dev/lispthing/node_modules/@jcubic/lips/src/lips.js:4208:28) at Object.exec (/Users/foobaz/Dev/lispthing/node_modules/@jcubic/lips/src/lips.js:4270:36) { code: [ '(fg.sync ".")', '(display (fg.sync "."))' ] }

jcubic commented 3 years ago

You're using outdated version of LIPS the README is for @beta version that handle dots inside symbols. The version that is in npm (without @beta) is heavily outdated. All features that was added to the language are in beta.

I need to document it somehow that people should not use default version.

In 0.20.1 that you've installed you need to use old syntax (that still work in beta) (. fg 'sync) or (.. fg.sync)

Beta versions are stable, I'm publishing new version when it's ready, like with normal release.