[ClojureScript] Re: Self-hosting Clojurescript - :context is important

2016-04-28 Thread Yehonathan Sharvit
It seems that when we pass :context :dummy, it behaves not like when not 
passing anything.

(cljs/eval-str (cljs/empty-state) " (def x 12) (if 45 23 21)" "bla" {:eval 
cljs/js-eval :context :expr} identity) ; => {:error #error {:message "ERROR", 
:data {:tag :cljs/analysis-error}, :cause #object[TypeError TypeError: 12 is 
not a function]}}
(cljs/eval-str (cljs/empty-state) " (def x 12) (if 45 23 21)" "bla" {:eval 
cljs/js-eval :context :dummy} identity) ; => {:ns cljs.user, :value 12}
(cljs/eval-str (cljs/empty-state) " (def x 12) (if 45 23 21)" "bla" {:eval 
cljs/js-eval :context :statements} identity); => {:ns cljs.user, :value 23}

It might be more convenient to look at it with KLIPSE: 
http://tinyurl.com/eval-str-context-confusion


On Tuesday, 26 April 2016 18:24:31 UTC+3, Thomas Heller  wrote:
> The :context basically tells the compiler if the return value is required 
> (:statement vs. :expr). A :statement does not need to return something and 
> "if" in javascript does not return something.
> 
> If an "if" is compiled with :expr it generates  (condition ? yes : no) 
> instead of "if" for :statement.
> 
> The compiler assumes :statement as the default for the top-level but when 
> working with a REPL that is not the case since you want the result, so :expr 
> must be set. The standard cljs repl wraps everything in a pr-str so that 
> problem does not show there.
> 
> Hope that made sense, but no it is not a bug.
> 
> Cheers,
> /thomas
> 
> 




> On Tuesday, April 26, 2016 at 4:07:12 PM UTC+2, J David Eisenberg wrote:
> > Sorry for the bad netiquette of responding to one's own post, but I am 
> > wondering if the compile in the condition that doesn't use {:content :expr} 
> > is a bug rather than something that should be expected.

(cljs/eval-str (cljs/empty-state) " (def x 12) (if 45 23 21)" "bla" {:eval 
cljs/js-eval :context :expr} identity)
{:error #error {:message "ERROR", :data {:tag :cljs/analysis-error}, :cause 
#object[TypeError TypeError: 12 is not a function]}}
klipse.compiler=> (cljs/eval-str (cljs/empty-state) " (def x 12) (if 45 23 21)" 
"bla" {:eval cljs/js-eval :context :statement} identity)
{:ns cljs.user, :value 12}
klipse.compiler=> (cljs/eval-str (cljs/empty-state) " (def x 12) (if 45 23 21)" 
"bla" {:eval cljs/js-eval :context :statements} identity)
{:ns cljs.user, :value 23}

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


[ClojureScript] Re: Self-hosting Clojurescript - :context is important

2016-04-26 Thread Thomas Heller
The :context basically tells the compiler if the return value is required 
(:statement vs. :expr). A :statement does not need to return something and "if" 
in javascript does not return something.

If an "if" is compiled with :expr it generates  (condition ? yes : no) instead 
of "if" for :statement.

The compiler assumes :statement as the default for the top-level but when 
working with a REPL that is not the case since you want the result, so :expr 
must be set. The standard cljs repl wraps everything in a pr-str so that 
problem does not show there.

Hope that made sense, but no it is not a bug.

Cheers,
/thomas


On Tuesday, April 26, 2016 at 4:07:12 PM UTC+2, J David Eisenberg wrote:
> Sorry for the bad netiquette of responding to one's own post, but I am 
> wondering if the compile in the condition that doesn't use {:content :expr} 
> is a bug rather than something that should be expected.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


[ClojureScript] Re: Self-hosting Clojurescript - :context is important

2016-04-26 Thread J David Eisenberg
Sorry for the bad netiquette of responding to one's own post, but I am 
wondering if the compile in the condition that doesn't use {:content :expr} is 
a bug rather than something that should be expected.

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.