-
Notifications
You must be signed in to change notification settings - Fork 127
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
Comments
Racket example > (define (this-prints)
(displayln "ok")
"return value")
> (displayln (string-append "ok: " (this-prints)))
ok
ok: return value |
Hi Vincenzo,
xtlang does not currently support variable length arguments. As a result
of this limitation println & printout are actually language keywords, not
functions. Behind the scenes the xtlang compiler unrolls the println into
a series of print calls. Once you have that in mind I'm sure the output
will make sense to you, although I agree not ideal.
Just by way of example try this:
($ (println (tuple (String "try to get first element:") (tref (testing)
0))))
Cheers,
Andrew.
…On Sun, Nov 17, 2019 at 10:39 AM Vincenzo Castiglia < ***@***.***> wrote:
Racket example
> (define (this-prints)
(displayln "ok")
"return value")
> (displayln (string-append "ok: " (this-prints)))
ok
ok: return value
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#370?email_source=notifications&email_token=AAEHPKIXJM4VX42TKAPG4QTQUCHE3A5CNFSM4JOHO3V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEH6CXQ#issuecomment-554688862>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEHPKINWZ22XTGGLNNJSLTQUCHE3ANCNFSM4JOHO3VQ>
.
|
I'll take a look at fixing this when I get a chance (i.e. better code
generation for println & printout).
Also just FYI this is how I would write testing
(bind-type MyType <i64,i64,double>)
(bind-func testing
(lambda ()
(let ((inner0 (MyType 0 1 3.3))
(inner1 (MyType 1 2 4.4))
(outer (tuple_ref inner0 inner1)))
;; what I get:
(println "outer:" outer)
(println "ok")
outer)))
…On Sun, Nov 17, 2019 at 11:43 AM Andrew Sorensen ***@***.***> wrote:
Hi Vincenzo,
xtlang does not currently support variable length arguments. As a result
of this limitation println & printout are actually language keywords, not
functions. Behind the scenes the xtlang compiler unrolls the println into
a series of print calls. Once you have that in mind I'm sure the output
will make sense to you, although I agree not ideal.
Just by way of example try this:
($ (println (tuple (String "try to get first element:") (tref (testing)
0))))
Cheers,
Andrew.
On Sun, Nov 17, 2019 at 10:39 AM Vincenzo Castiglia <
***@***.***> wrote:
> Racket example
>
> > (define (this-prints)
> (displayln "ok")
> "return value")
> > (displayln (string-append "ok: " (this-prints)))
> ok
> ok: return value
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#370?email_source=notifications&email_token=AAEHPKIXJM4VX42TKAPG4QTQUCHE3A5CNFSM4JOHO3V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEH6CXQ#issuecomment-554688862>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAEHPKINWZ22XTGGLNNJSLTQUCHE3ANCNFSM4JOHO3VQ>
> .
>
|
Incidentally, if you're wondering why code generation, it's because println
and printout were added to the compiler in the very early days before
xtlang had macro's. We should change this!
Easy enough to do yourself in xtlang these days - something like this:
(bind-macro (myPrintln . args)
(let ((argNames (map (lambda (x)
(string->symbol (string-append "arg" (number->string
x))))
(range (length args)))))
`(let (,@(map (lambda (n x) (list n x)) argNames args))
(println ,@(map (lambda (n a) (if (string? a) a n)) argNames
args)))))
Then you should get something like you're expecting with
($ (myPrintln "try to get first element:" (tref (testing) 0)))
…On Sun, Nov 17, 2019 at 11:57 AM Andrew Sorensen ***@***.***> wrote:
I'll take a look at fixing this when I get a chance (i.e. better code
generation for println & printout).
Also just FYI this is how I would write testing
(bind-type MyType <i64,i64,double>)
(bind-func testing
(lambda ()
(let ((inner0 (MyType 0 1 3.3))
(inner1 (MyType 1 2 4.4))
(outer (tuple_ref inner0 inner1)))
;; what I get:
(println "outer:" outer)
(println "ok")
outer)))
On Sun, Nov 17, 2019 at 11:43 AM Andrew Sorensen ***@***.***>
wrote:
> Hi Vincenzo,
>
> xtlang does not currently support variable length arguments. As a result
> of this limitation println & printout are actually language keywords, not
> functions. Behind the scenes the xtlang compiler unrolls the println into
> a series of print calls. Once you have that in mind I'm sure the output
> will make sense to you, although I agree not ideal.
>
> Just by way of example try this:
>
> ($ (println (tuple (String "try to get first element:") (tref (testing)
> 0))))
>
> Cheers,
> Andrew.
>
>
> On Sun, Nov 17, 2019 at 10:39 AM Vincenzo Castiglia <
> ***@***.***> wrote:
>
>> Racket example
>>
>> > (define (this-prints)
>> (displayln "ok")
>> "return value")
>> > (displayln (string-append "ok: " (this-prints)))
>> ok
>> ok: return value
>>
>> —
>> You are receiving this because you are subscribed to this thread.
>> Reply to this email directly, view it on GitHub
>> <#370?email_source=notifications&email_token=AAEHPKIXJM4VX42TKAPG4QTQUCHE3A5CNFSM4JOHO3V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEH6CXQ#issuecomment-554688862>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/AAEHPKINWZ22XTGGLNNJSLTQUCHE3ANCNFSM4JOHO3VQ>
>> .
>>
>
|
Thanks for the replies, Should this issue stay open until println is replaced with a macro? |
yes, you can leave it open
…On Mon, Nov 18, 2019 at 6:01 AM Vincenzo Castiglia ***@***.***> wrote:
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?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#370?email_source=notifications&email_token=AAEHPKIRKNGZBOMP7MY7UZTQUGPJTA5CNFSM4JOHO3V2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEIUPEQ#issuecomment-554780562>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEHPKJQLAZJW7MQKWJ7LDLQUGPJTANCNFSM4JOHO3VQ>
.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assume the following code:
The output is:
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:
The text was updated successfully, but these errors were encountered: