egallesio / STklos

STklos Scheme
http://stklos.net
GNU General Public License v2.0
69 stars 17 forks source link

Is `require` working as expected? #599

Closed jpellegrini closed 1 year ago

jpellegrini commented 1 year ago

If I use require, STklos says it's ok, but doesn't load the library:

stklos> (require "scheme/flonum")
"scheme/flonum"
stklos> fl-pi
**** Error:
%execute: symbol `fl-pi' unbound in module `stklos'
    (type ",help" for more information)

If I use import, it works:

stklos> (import (scheme flonum))
stklos> fl-pi
3.14159265358979

Or,

stklos> (import scheme/flonum)
stklos> fl-pi
3.14159265358979
egallesio commented 1 year ago

Yes, it works:

$ stklos  -dd 
%guess-pathname: trying "/home/eg/.stklos/stklosrc"
;; Loading file "/home/eg/.stklos/stklosrc".
;; File "/home/eg/.stklos/stklosrc" loaded.
%guess-pathname: trying "/home/eg/Projects/STklos/lib/readline-complete.so"
;; Loading file "/home/eg/Projects/STklos/lib/readline-complete.so".
;; File "/home/eg/Projects/STklos/lib/readline-complete.so" loaded.
  \    STklos version 1.70.1478 (unstable -- 195d9bfb)
   \   Copyright (C) 1999-2023 Erick Gallesio <eg@stklos.net>
  / \  [Linux-6.1.49-1-MANJARO-x86_64/pthreads/readline/utf8]
 /   \ Type ',h' for help
stklos> (require "scheme/flonum")
%guess-pathname: trying "scheme/flonum"
%guess-pathname: trying "scheme/flonum.so"
%guess-pathname: trying "scheme/flonum.ostk"
%guess-pathname: trying "scheme/flonum.stk"
%guess-pathname: trying "scheme/flonum.sld"
%guess-pathname: trying "scheme/flonum.scm"
%guess-pathname: trying "/home/eg/Projects/STklos/lib/scheme/flonum"
%guess-pathname: trying "/home/eg/Projects/STklos/lib/scheme/flonum.so"
%guess-pathname: trying "scheme/flonum"
%guess-pathname: trying "scheme/flonum.so"
%guess-pathname: trying "scheme/flonum.ostk"
%guess-pathname: trying "scheme/flonum.stk"
%guess-pathname: trying "scheme/flonum.sld"
%guess-pathname: trying "scheme/flonum.scm"
%guess-pathname: trying "/home/eg/Projects/STklos/lib/scheme/flonum"
%guess-pathname: trying "/home/eg/Projects/STklos/lib/scheme/flonum.so"
%guess-pathname: trying "scheme/flonum"
%guess-pathname: trying "scheme/flonum.so"
%guess-pathname: trying "scheme/flonum.ostk"
%guess-pathname: trying "scheme/flonum.stk"
%guess-pathname: trying "scheme/flonum.sld"
%guess-pathname: trying "scheme/flonum.scm"
%guess-pathname: trying "/home/eg/Projects/STklos/lib/scheme/flonum"
%guess-pathname: trying "/home/eg/Projects/STklos/lib/scheme/flonum.so"
%guess-pathname: trying "/home/eg/Projects/STklos/lib/scheme/flonum.so"
;; Loading file "/home/eg/Projects/STklos/lib/scheme/flonum.so".
;; File "/home/eg/Projects/STklos/lib/scheme/flonum.so" loaded.
"scheme/flonum"

As you can see, the file is found and loaded. However, require is like load (load if not already loaded). It is not aware of modules or libraries. On the other hand, import is a sort of "require before import" and then import.

If the file contains only one library/module, I think that importing is now a better solution than requiring IMO.

jpellegrini commented 1 year ago

Ah, I see! I thought that importing would be automatic when one does (require x), wich x being the name of a Scheme library. Thanks a lot @egallesio !