Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions aren't loaded correcly #6

Open
aarroyoc opened this issue Dec 9, 2024 · 0 comments
Open

Functions aren't loaded correcly #6

aarroyoc opened this issue Dec 9, 2024 · 0 comments

Comments

@aarroyoc
Copy link

aarroyoc commented Dec 9, 2024

Take a file named primes.shen with this content:

(define prime?
 X -> (prime-h? X (isqrt X) 2))

(define isqrt
 X -> (isqrt-help X 1))

(define isqrt-help
 X Y -> Y        where (= (* Y Y) X)
 X Y -> (- Y 1)  where (> (* Y Y) X)
 X Y -> (isqrt-help X (+ Y 1)))

(define prime-h?
 X Max Div -> true      where (> Div Max)
 X Max Div -> false     where (integer? (/ X Div))
 X Max Div -> (prime-h? X Max (+ 1 Div)))

Now, load it into the REPL:

(0-) (load "/home/aarroyoc/dev/shen/primes.shen")
prime?
isqrt
isqrt-help
prime-h?
loaded

(1-) (prime? 12)
error: application: not a procedure;
 expected a procedure that can be applied to arguments
  given: 'isqrt
  context...:
   body of top-level
   .../lang/syntax-utils.rkt:433:44: prime?
   .../private/parse-interp.rkt:643:50
   .../scryer-shen/repl.rkt:28:0: shen-repl
   body of '#%mzc:repl



(2-) (load "/home/aarroyoc/dev/shen/primes.shen")
prime?
isqrt
error: isqrt-help: identifier's binding is ambiguous
  in: isqrt-help
  context...:
   #(-3699 interned function) #(8132 local) #(8135 local) #(8136 intdef)
   #(8147 local) #(8148 intdef) #(8150 local) #(8157 intdef)
   #(8162 local) #(8163 intdef) #(8166 local) #(8167 letrec-body)
   #(8169 intdef) #(8172 local) #(8173 intdef) #(8175 local)
   #(8176 intdef) #(8178 local) #(8179 intdef) #(8181 local)
   #(8182 intdef) [common scopes]
  matching binding...:
   local
   #(8132 local) [common scopes]
  matching binding...:
   #(isqrt-help.1 #<module-path-index:top-level> 0)
   #(-3699 interned function) [common scopes]
  common scopes...:
   #(0 module) #(7395/2 module top-level)
  context...:
   .../private/stxparam.rkt:63:2
   .../private/parse-interp.rkt:643:50
   .../lang/load.rkt:112:4
   .../lang/load.rkt:108:0: body of top-level
   .../private/parse-interp.rkt:643:50
   .../scryer-shen/repl.rkt:28:0: shen-repl
   body of '#%mzc:repl



(3-) (prime? 12)
false

As it's visible from the interaction, the first load didn't really load some functions, so trying to execute them gives an error. Reloading again, even if it shows an error, fixes the issue. I suspect it has to do with the order in which functions are defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant