Re: Functions referenced in macro-expansions cannot be internal?

2016-04-01 Thread Erik Assum
On condp, case etc. Alex Miller wrote a blog post on their performance a while ago: http://insideclojure.org/2015/04/27/poly-perf/ Erik. -- i farta > Den 1. apr. 2016 kl. 13.03 skrev Kenneth Tilton : > > > >> On Fri, Apr 1, 2016 at 2:41 AM, Erik Assum wrote: >> Not at all answering your

Re: Functions referenced in macro-expansions cannot be internal?

2016-04-01 Thread Kenneth Tilton
On Fri, Apr 1, 2016 at 2:41 AM, Erik Assum wrote: > Not at all answering your question, but I would strongly suggest to at > least deref `me` before calling the function, so it’s definition would be > more like: > > (defn svr [me slot] >(when-let [sval (slot me)] >(if (jz-ref sval) >

Re: Functions referenced in macro-expansions cannot be internal?

2016-03-31 Thread Erik Assum
Not at all answering your question, but I would strongly suggest to at least deref `me` before calling the function, so it’s definition would be more like: (defn svr [me slot] (when-let [sval (slot me)] (if (jz-ref sval) (condp type @sval) :jzi (:val @sval)

Functions referenced in macro-expansions cannot be internal?

2016-03-31 Thread hiskennyness
With Jellz (ne Cells in CL) I want to make reading an attribute of an object seem like a normal function call, but reading a cell actually looks like this: (defn- svr [slot me] ;; svr = slot-value-read, me = short version of "self" > (when-let [sval (slot @me)] > (cond > (jz-ref? sval

Re: Stumped: unable to resolve symbol in macro expansion

2014-07-22 Thread Dave Tenny
Doh! Major face palm. I had such a bad case of tunnel vision on the macro definition I forgot to look up the stack once I'd fixed the macro. Thanks. Good to have extra eyes. On Mon, Jul 21, 2014 at 1:04 PM, Matthew DeVore wrote: > I haven't taken the time to fully grok your macro, but the e

Re: Stumped: unable to resolve symbol in macro expansion

2014-07-21 Thread Matthew DeVore
I haven't taken the time to fully grok your macro, but the error is not the fault of your macro, but of the function invocation. (foo x) is causing the error because x is undefined. foo is a plain function, not a macro, so it tries to evaluate each argument. (foo 'x) works fine for me, as does (

Re: Stumped: unable to resolve symbol in macro expansion

2014-07-21 Thread Dave Tenny
In my case, I'm trying to use a the expression '[x] that is available to the macro in the resulting product. So I don't want the value of x at all, just a vector with the symbol x. That vector is in a variable I have in the macro named 'positional-parameters', so I substitute '~positional-paramet

Stumped: unable to resolve symbol in macro expansion

2014-07-20 Thread Matthew DeVore
I don't have a Clojure REPL handy at the moment but it looks like the x symbol is being resolved in the macro context rather than the expansion context. In the macro source, where you have a plain x, try to replace it with ~'x ... This blog post may be relevant: http://amalloy.hubpages.com/hub/

Re: NullPointerException when creating protocol in macro

2013-06-07 Thread Vincent
Thanks everyone for your answers. I must say I'm quite mystified as to why Stuart's version works. I ended up defining a function that has the same signature as the protocol, and whose first argument wraps a function that contains the appropriate code. Vincent On Wednesday, 5 June 2013 23:57:

Re: NullPointerException when creating protocol in macro

2013-06-05 Thread Softaddicts
Legal but comparable to a hidden side effect with all the pitfalls that can derive from this. It's not a compiler issue, more a discipline issue. Having a helper macro like Stuart suggest is acceptable to me if it's called at top level, it's always done. There's less ambiguity. Using def/defn i

Re: NullPointerException when creating protocol in macro

2013-06-05 Thread Stuart Sierra
On Wed, Jun 5, 2013 at 7:35 PM, Colin Fleming wrote: > Given this, are there any forms that are genuinely top-level from the > compiler's point of view? It's never explicitly enforced, just a consequence of how the compiler creates and loads Java classes. Generally, the things which compile dir

Re: NullPointerException when creating protocol in macro

2013-06-05 Thread Colin Fleming
*`defprotocol` is a top-level form...* This is interesting, and it's something I've wondered about. As far as I can tell, there's really no distinction between top-level forms and other forms, for example this is legal and works: (defn define-my-functions [] (defn test-1 [] 1) (defn test-

Re: NullPointerException when creating protocol in macro

2013-06-05 Thread Stuart Sierra
Hi Vincent, `defprotocol` is a top-level form, not really meant to be mixed with value-returning expressions like `fn`. Protocols are always global because of how they compile into Java interfaces. Here's one way to make it work, by defining a symbol instead of returning a function: (defmacro

NullPointerException when creating protocol in macro

2013-06-05 Thread Vincent
I’m trying to write a macro that defines a protocol and a function that, when called, returns an implementation of that protocol. I’ve reduced the code to the following example: (defmacro create-protocol [protocol implementation] (let [[protocol-name signature] protocol] `(do (defpro

Re: generate two defns in macro

2012-08-21 Thread jaime
I don't see there's a way to eliminate out most parenthesis like this either. Maybe you can try to spit them out to somewhere and then read them back again...but you probably don't want to do this. ;-) 在 2012年8月21日星期二UTC+8下午11时00分31秒,Maris写道: > > > Nothing is wrong with do block.I just thoug

Re: generate two defns in macro

2012-08-21 Thread Maris
Nothing is wrong with do block.I just thought maybe there is some trick Fair enough. On Tuesday, 21 August 2012 15:55:04 UTC+1, lpetit wrote: > > Hello, > > What's wrong with having 2 fns inside the top level do ? > > In Clojure, top level dos are split so that their children forms ar

Re: generate two defns in macro

2012-08-21 Thread Laurent PETIT
Hello, What's wrong with having 2 fns inside the top level do ? In Clojure, top level dos are split so that their children forms are evaluated in sequence, as if you would have written them without the do. HTH, -- Laurent 2012/8/21 Maris > I want a macro that generates two defn's. > > (defn

Re: generate two defns in macro

2012-08-21 Thread Maik Schünemann
What speaks against two defns in a do. It works as if you write two defns in normal code. Actually I find this very useful to do because you don't have additionally complexity for returning multiple sexps Am 21.08.2012 16:42 schrieb "Maris" : > I want a macro that generates two defn's. > > (defn v

generate two defns in macro

2012-08-21 Thread Maris
I want a macro that generates two defn's. (defn vote-suspend [this] (deref (.state this))) (defn vote-resume [this state] (reset! (.state this) state)) I have written this: (defmacro suspendable [prefix] `(do (defn ~(symbol (str prefix "suspend")) [~'this] (deref (.state ~'this))) (def

Re: Errors w/ dynamic symbols in macro-utils or monads?

2011-12-02 Thread Andrew
ah: http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go clojure.contrib.monads - Migrated to clojure.algo.monads - lead Konrad Hinsen . - Status: latest build status

Re: Errors w/ dynamic symbols in macro-utils or monads?

2011-12-02 Thread Andrew
Does this still happen for you? It appears to still be the case in my environment. Dropping back to Clojure *1.2.1* seems to work but in addition to trying out monads, I need to use a library (clj-webdriver) that relies on Clojure *1.3.0* What to do? -- You received this message because y

Re: why expressions in macro are not evaluated?

2011-09-17 Thread jingguo
Michael, thanks for your explanation. I have used dorun to solve my problem following your suggestion. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are m

Re: why expressions in macro are not evaluated?

2011-09-14 Thread Michael Gardner
On Sep 13, 2011, at 2:39 AM, jingguo wrote: > I get a_message printed twice if I paste the code in a clojure REPL. > But I save the code into a file called foo.clj and use "clj foo.clj" > to run it. I get nothing in stdout. It seems that (printf "a_message > \n") > is not evaluated. Can anybody ex

why expressions in macro are not evaluated?

2011-09-14 Thread jingguo
I write a simple macro and an invocation of the macro. Here is the code: (defmacro my-macro [& body] `(for [cur-date# ["2011-09-04" "2011-09-05"]] (do ~@body) ) ) (my-macro (printf "a_message\n") ) I get a_message printed twice if I paste the code in a clojure REPL. But I save the co

Errors w/ dynamic symbols in macro-utils or monads?

2011-01-06 Thread Chris Riddoch
Hi, everyone. With the changes to dynamic symbols in 1.3.0-snapshot, a number of modules of contrib/ seem unable to function. I'm trying to see if I can get fnparse to run under the master branch, and it wants contrib/monads, which in turn wants contrib/macro-utils. The following error happens a

Re: Symbol substitution in macro

2010-08-04 Thread Kyle Schaffrick
On Wed, 4 Aug 2010 14:58:46 -0400 Andrew Boekhoff wrote: > Hi, > > > because the symbol's namespace is then nil, and you still can't > > tell if they're shadowing it with a let binding, or have renamed it > > with :as. > > > > If the namespace is nil then its either been :used or :required.

Re: Symbol substitution in macro

2010-08-04 Thread Andrew Boekhoff
Hi, > because the symbol's namespace is then nil, and you still can't tell if > they're shadowing it with a let binding, or have renamed it with :as. > If the namespace is nil then its either been :used or :required. You could check ns-refers to see if its been :used. If its been shadowed the

Re: Symbol substitution in macro

2010-08-03 Thread Kyle Schaffrick
On Mon, 2 Aug 2010 07:23:12 -0400 Andrew Boekhoff wrote: > > On Sunday 01 August 2010 21:34:16 Kyle Schaffrick wrote: > > > Hello, > > > > I'm trying to write a library with two main parts. The first is a > > macro, I'll call it 'with-feature, that walks through forms passed > > inside it, and an

Re: Symbol substitution in macro

2010-08-02 Thread Andrew Boekhoff
On Sunday 01 August 2010 21:34:16 Kyle Schaffrick wrote: Hi, The following technique seems to work for finding out if you've been aliased: (ns somewhere.trial) (let [here *ns*] (defmacro whats-my-name [] (some (fn [[k v]] (when (= here v) `(quote ~k))) (ns-aliases *ns*)

Re: Symbol substitution in macro

2010-08-01 Thread Heinz N. Gies
On Aug 2, 2010, at 3:34 , Kyle Schaffrick wrote: > Hello, > > I'm trying to write a library with two main parts. The first is a > macro, I'll call it 'with-feature, that walks through forms passed > inside it, and any time it sees a call to another function in my > library, 'feature, do some tra

Symbol substitution in macro

2010-08-01 Thread Kyle Schaffrick
Hello, I'm trying to write a library with two main parts. The first is a macro, I'll call it 'with-feature, that walks through forms passed inside it, and any time it sees a call to another function in my library, 'feature, do some transformations. The problem I'm concerned about is as follows: W

Re: Removing (gensym) in macro

2010-02-08 Thread Laurent PETIT
2010/2/8 Meikel Brandmeyer : > Hi, > > On Feb 8, 2:06 pm, Roman Roelofsen > wrote: > >> Ah, that makes sense, thanks! Is using (gensym) the common solution >> here? So far I thought that (gensym) is more a internal function that >> I normally never need to call directly. > > In such a case using g

Re: Removing (gensym) in macro

2010-02-08 Thread Meikel Brandmeyer
Hi, On Feb 8, 2:06 pm, Roman Roelofsen wrote: > Ah, that makes sense, thanks! Is using (gensym) the common solution > here? So far I thought that (gensym) is more a internal function that > I normally never need to call directly. In such a case using gensym is the normal solution. When you don'

Re: Removing (gensym) in macro

2010-02-08 Thread Roman Roelofsen
> It doesn't work because the scope of lname# is limited to the `(). > However lname is used in a ~@() which leaves the `() and enters the > enclosing environment (in this case the macros). There the lname# is > not valid. Ah, that makes sense, thanks! Is using (gensym) the common solution here? S

Re: Removing (gensym) in macro

2010-02-08 Thread Roman Roelofsen
> I don't see a compelling reason for such a macro. At least not in this > simple case. I agree. As I said, the purpose of this macro was purely for learning and understanding macros ;-) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this

Re: Removing (gensym) in macro

2010-02-08 Thread Meikel Brandmeyer
Hi, On Feb 8, 12:14 pm, Michael Wood wrote: > user=> (doto (java.util.ArrayList.) > (.add "1") > (.add "2")) > # Oops. Yes. You need doto instead of ->. Sorry, my mistake. > > Is it possible to create the macro without the (gensym) call? I wasn't > > able to use something like lname#. > > Sorr

Re: Removing (gensym) in macro

2010-02-08 Thread Michael Wood
On 8 February 2010 12:45, Roman Roelofsen wrote: > Hi, > > just for practicing Clojure's macros I wrote the following > create-java-list macro. > > (defmacro create-java-list >  [& forms] >  (let [prefixfn (fn [obj form] (cons (symbol ".") (cons obj form))) >        lname (gensym)] >    `(let [~ln

Re: Removing (gensym) in macro

2010-02-08 Thread Meikel Brandmeyer
Hi, On Feb 8, 11:45 am, Roman Roelofsen wrote: > just for practicing Clojure's macros I wrote the following > create-java-list macro. > > (defmacro create-java-list >   [& forms] >   (let [prefixfn (fn [obj form] (cons (symbol ".") (cons obj form))) >         lname (gensym)] >     `(let [~lname

Removing (gensym) in macro

2010-02-08 Thread Roman Roelofsen
Hi, just for practicing Clojure's macros I wrote the following create-java-list macro. (defmacro create-java-list [& forms] (let [prefixfn (fn [obj form] (cons (symbol ".") (cons obj form))) lname (gensym)] `(let [~lname (java.util.ArrayList.)] ~@(map (partial prefixfn lnam

How to interpret nested back quote in Macro?

2009-01-02 Thread wubbie
Hi all, Here is the code from Stu's CL translation. (defmacro check [& forms] `(do ~@(map (fn [f] `(report-result ~f '~f)) forms))) And report-result is: (defn report-result [result form] (println (format "%s: %s" (if result "pass" "FAIL") (pr-str form An example run is: (chec

Re: eval in macro: No method for dispatch value

2008-12-03 Thread Michiel de Mare
Thank you very much for this detailed explanation! Michiel de Mare On Dec 3, 2:47 pm, Rich Hickey <[EMAIL PROTECTED]> wrote: > On Dec 3, 6:58 am, Michiel de Mare <[EMAIL PROTECTED]> wrote: > > > > > Indeed, (print-dup (new StringBuffer) (new java.io.StringWriter)) > > throws the same exception.

Re: eval in macro: No method for dispatch value

2008-12-03 Thread Rich Hickey
On Dec 3, 6:58 am, Michiel de Mare <[EMAIL PROTECTED]> wrote: > Indeed, (print-dup (new StringBuffer) (new java.io.StringWriter)) > throws the same exception. > But (new StringBuffer) in the REPL prints the stringbuffer just fine. > > Why does the exception only get triggered in macros? > > And do

Re: eval in macro: No method for dispatch value

2008-12-03 Thread Michiel de Mare
Indeed, (print-dup (new StringBuffer) (new java.io.StringWriter)) throws the same exception. But (new StringBuffer) in the REPL prints the stringbuffer just fine. Why does the exception only get triggered in macros? And doesn't print-dup need a default for unknown classes? On Dec 3, 12:23 pm, M

Re: eval in macro: No method for dispatch value

2008-12-03 Thread Meikel Brandmeyer
Hi, On 3 Dez., 12:04, Michiel de Mare <[EMAIL PROTECTED]> wrote: > This has nothing to do with eval. The following fails too: > > (defmacro foo [] (new StringBuffer)) > (foo) The results at the Repl are printed via pr-on and obviously print-dup doesn't know how to print a StringBuffer. Sincerel

Re: eval in macro: No method for dispatch value

2008-12-03 Thread Michiel de Mare
This has nothing to do with eval. The following fails too: (defmacro foo [] (new StringBuffer)) (foo) On Dec 3, 3:22 am, Stuart Halloway <[EMAIL PROTECTED]> wrote: > Hi Michiel, > > eval is for form data, so I am more surprised that it works for   > ArrayList than that it fails for StringBuffer

Re: eval in macro: No method for dispatch value

2008-12-02 Thread Stuart Halloway
Hi Michiel, eval is for form data, so I am more surprised that it works for ArrayList than that it fails for StringBuffer. Stu > After playing around with macros, I ran into this problem with Clojure > (the latest version from github). The following code throws an > IllegalArgumentException:

eval in macro: No method for dispatch value

2008-12-02 Thread Michiel de Mare
After playing around with macros, I ran into this problem with Clojure (the latest version from github). The following code throws an IllegalArgumentException: "No method for dispatch value: class java.lang.StringBuffer" (defmacro wrap [h] (eval h)) (wrap (new StringBuffer)) But this works fine:

Re: "in" macro

2008-08-25 Thread Rich Hickey
On Aug 18, 12:57 am, Parth Malwankar <[EMAIL PROTECTED]> wrote: > On Aug 18, 1:57 am, Randall R Schulz <[EMAIL PROTECTED]> wrote: > > > On Sunday 17 August 2008 07:08, Parth Malwankar wrote: > > > > I am trying to create a "in" macro. > > >