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

question: println has lazy evaluation, is this right? #370

Open
CastixGitHub opened this issue Nov 17, 2019 · 6 comments
Open

question: println has lazy evaluation, is this right? #370

CastixGitHub opened this issue Nov 17, 2019 · 6 comments

Comments

@CastixGitHub
Copy link

Assume the following code:

 (bind-alias my_type <i64,i64,double>*)
 (bind-func testing:[<my_type,my_type>*]* 100000
   (lambda ()
     (let ((outer:<my_type,my_type>* (zalloc)))
       (begin
         (let ((inner0:my_type (zalloc))
               (inner1:my_type (zalloc)))
           (tfill! inner0 0 1 3.3)
           (tfill! inner1 1 2 4.4)
           (tset! outer 0 inner0)
           (tset! outer 1 inner1))
         ;; what I get:                                                                                                                            
         (println "outer:" outer)
         (println "ok")
         outer))))
 ($ (println "try to get first element:" (tref (testing) 0)))

The output is:

 try to get first element: outer: <<0,1,3.300000>,<1,2,4.400000>>                                                                              
 ok                                                                                                                                            
 <0,1,3.300000>

I see that println prints out one argument each time, without eager evaluation, when the evaluation has side effects (such as println) the output seems broken.
I would expect this output:

outer: <<0,1,3.300000>,<1,2,4.400000>>                                                                              
ok                                                                                                                                            
try to get first element:  <0,1,3.300000>
@CastixGitHub
Copy link
Author

Racket example

> (define (this-prints)
    (displayln "ok")
    "return value")
> (displayln (string-append "ok: " (this-prints)))
ok
ok: return value

@digego
Copy link
Owner

digego commented Nov 17, 2019 via email

@digego
Copy link
Owner

digego commented Nov 17, 2019 via email

@digego
Copy link
Owner

digego commented Nov 17, 2019 via email

@CastixGitHub
Copy link
Author

Thanks for the replies,
As I'm still a beginner with lisp/scheme too, and xtlang reference docs is still lacking of macros explainations, can you share some resource from where we can learn? Thanks.

Should this issue stay open until println is replaced with a macro?

@digego
Copy link
Owner

digego commented Nov 17, 2019 via email

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

2 participants