Giter Site home page Giter Site logo

Comments (16)

ashinn avatar ashinn commented on August 16, 2024 2

Updated the docs as described and added a new warning, hopefully this is clear enough:

WARNING: exception inside undefined operator: define
WARNING: did you forget to import a language? e.g. (import (scheme base))
ERROR on line 4 of file foo.scm: dotted list in source: (print x . rest)
  called from <anonymous> on line 1268 of file ./lib/init-7.scm
  called from <anonymous> on line 800 of file ./lib/init-7.scm

from chibi-scheme.

ashinn avatar ashinn commented on August 16, 2024

You didn't import define, or any bindings at all, which is why you get

"WARNING: exception inside undefined operator: define"

Obviously if define is undefined then the expression is treated not as syntax but as a normal function application, where a dotted list is illegal syntax in pretty much every lisp.

Add '(import (scheme base))` to the top of your script to import define.

from chibi-scheme.

jcubic avatar jcubic commented on August 16, 2024

I was not able to find this information in the documentation. Maybe I'm missing something but actually, I don't see any Scheme code in docs at all. I would add this as the first thing in the docs on how to use the system. If someone is new to Chibi they have no clue how to use it.

To add: none of the other Scheme implementations, that I was testing, work like this.

from chibi-scheme.

mnieper avatar mnieper commented on August 16, 2024

from chibi-scheme.

lassik avatar lassik commented on August 16, 2024

Correct me if I'm wrong, but Chibi expects a source file to be a "program" in R7RS terminology. R7RS section 5.1 says:

A Scheme program consists of one or more import declarations followed by a sequence of expressions and definitions.

This is not obvious and the error messages are confusing. A specification is not a good tutorial or manual.

from chibi-scheme.

ashinn avatar ashinn commented on August 16, 2024

I had added the warning specifically for this case, thinking it was clear enough. Let me add a "Did you forget to import a language?" clause.

from chibi-scheme.

jcubic avatar jcubic commented on August 16, 2024

I would add information to the documentation on how to write cross-compatible code.

(cond-expand
 (chibi
  (import (scheme base)
          (chibi)))
 (else))

Only Chibi is required to import something to do anything.

from chibi-scheme.

mnieper avatar mnieper commented on August 16, 2024

I would add information to the documentation on how to write cross-compatible code.

(cond-expand
 (chibi
  (import (scheme base)
          (chibi)))
 (else))

Only Chibi is required to import something to do anything.

Any conforming implementation of R7RS programs (see section 5.1 in the R7RS) starts with an empty environment unless something is imported. From the cited section: "The initial environment of a program is empty, so at least one import declaration is needed to introduce initial bindings."

This is different to REPL semantics (see section 5.7). Here, the standard says: "For convenience and ease of use, the
global Scheme environment in a REPL must not be empty, but must start out with at least the bindings provided by the base library."

Chibi implements both conforming programs and a conforming REPL.

from chibi-scheme.

jcubic avatar jcubic commented on August 16, 2024

Does it mean that only Chibi is a real R7RS compilat Scheme Implementation?

Anyway, this should be in the documentation, since no other Scheme I've tested works like this, so it's at least confusing (especially to newcomers).

I would add a section like this:

R7RS Scheme Conformance

Because the Chibi Scheme is fully compatible with R7RS it requires at least of import of base module to work.

e.g.:

(import (scheme base))

from chibi-scheme.

lassik avatar lassik commented on August 16, 2024
(cond-expand
 (chibi
  (import (scheme base)
          (chibi)))
 (else))

A cond-expand is not necessary if you are targeting R7RS implementations.

(import (scheme base)) works in all of them. (Try it!)

(import (chibi)) is not needed to run portable programs in Chibi.

from chibi-scheme.

lassik avatar lassik commented on August 16, 2024

Does it mean that only Chibi is a real R7RS [compliant] Scheme Implementation?

It does not mean that.

The issue is confusing because "program" is a common word, but R7RS uses the word "program" in its own exact sense.

R7RS says how its "programs" behave. But RnRS does not cover the command line usage of Scheme implementations. So it does not dictate that chibi-scheme foo.scm or lips foo.scm should interpret foo.scm as an R7RS program. The implementation is free to interpret foo.scm as something else.

Anyway, this should be in the documentation, since no other Scheme I've tested works like this, so it's at least confusing (especially to newcomers).

+1

from chibi-scheme.

lassik avatar lassik commented on August 16, 2024

Historically, (import ...) was added to Scheme quite late, in R6RS and R7RS. import was not a part of R5RS. That's probably the reason why many Scheme implementations import a lot of stuff by default.

from chibi-scheme.

mnieper avatar mnieper commented on August 16, 2024

from chibi-scheme.

lassik avatar lassik commented on August 16, 2024

Gauche at least detects a source file that starts with (import ...) and switches to R7RS mode. If the file starts with something else, it stays in its traditional mode. This is slightly confusing, but works well once you know it.

from chibi-scheme.

ashinn avatar ashinn commented on August 16, 2024

The Chibi docs are very explicit about being a native R7RS implementation. All examples, scripts and tests in the distribution begin with an import (as does the sample program in the R7RS spec). I can add an extra note to the docs, but it's more important to make the error message clearer for people who don't read the docs.

As Marc points out, the reason R7RS chose not to provide a default language in programs is explicit control of bindings, to avoid import conflicts and in particular for clean macro semantics.

However as noted above, the Chibi repl does provide a (run-time configurable) default language and you can always load the script in repl mode with chibi-scheme < foo.scm (or with the -l option).

Note the (cond-expand ...) suggestion is pointless because it's not needed for R7RS implementations, and if you abandon even R7RS compatibility it's impractical to write useful programs.

from chibi-scheme.

lassik avatar lassik commented on August 16, 2024

Excellent. Thank you.

from chibi-scheme.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.