Re: Looking for a better way

2010-12-16 Thread Emeka
Laurent and Robert,

Thank you all.


On Thu, Dec 16, 2010 at 9:44 AM, Laurent PETIT wrote:

> Indeed !
>
> I was stuck in the macro thinking, thanks for getting us out of it !
>
> And then this solution not only works for literal strings:
>
> user=> (foo (str "yo" "man"))
> #'user/yoman
> user=> yoman
> "yoman"
> user=>
>
> 2010/12/16 Robert McIntyre 
>
> no need to use macros at all:
>>
>> (defn foo
>>  "creates a symbol named s with the value s in the current namespace "
>>  [s]
>> (intern *ns* (symbol s) s))
>>
>> that is, assuming I got the use case right.
>>
>> --Robert McIntyre
>>
>>
>> On Wed, Dec 15, 2010 at 8:00 AM, Laurent PETIT 
>> wrote:
>> > 2010/12/15 Emeka 
>> >>
>> >> Helllo All,
>> >> Is there a better way of doing this?
>> >> (defmacro foo [string] (let[b# string f# (symbol b#)] `(def ~f#  ~b#)))
>> >
>> > Hello,
>> >
>> > What is it supposed to be used ?
>> >
>> > What do you expect the macroexpansion to look like ?
>> >
>> > As is stands, your example can go without the ending #'s since they
>> aren't
>> > declared inside the returned quoted expr. They're useless.
>> >
>> > So having
>> >
>> > (defmacro foo [string] (let [b string f (symbol string)] `(def ~f ~b)))
>> >
>> > But now, string is not (as you may think) evaluated within the let in
>> the
>> > macro. string is just an immutable datastructure containing "as is" what
>> has
>> > been passed to foo. So if what you pass to foo is something which
>> > "evaluates" to a string, for example a string concatenation expression
>> as
>> > (str "the-" "value"), then the code will not do what it suggests it's
>> doing
>> > :
>> >
>> > user=> (defmacro foo [string] (let[b# string f# (symbol b#)] `(def ~f#
>> > ~b#)))
>> > #'user/foo
>> > user=> (foo (str "the-" "value"))
>> > java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast
>> to
>> > java.lang.String (NO_SOURCE_FILE:0)
>> > user=> (macroexpand '(foo (str "the-" "value")))
>> > java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast
>> to
>> > java.lang.String (NO_SOURCE_FILE:0)
>> > user=>
>> >
>> >
>> > Now, if you just want the macro to take literal strings as input, then
>> the
>> > code can be further simplified to :
>> >
>> > (defmacro foo [string] `(def ~(symbol string) ~string))
>> >
>> > user=> (defmacro foo [string] `(def ~(symbol string) ~string))
>> > #'user/foo
>> > user=> (foo "the-string")
>> > #'user/the-string
>> > user=> the-string
>> > "the-string"
>> > user=> (macroexpand '(foo "the-string"))
>> > (def the-string "the-string")
>> > user=>
>> >
>> > HTH,
>> >
>> > --
>> > Laurent
>> >
>> > --
>> > 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 moderated - please be patient with
>> your
>> > first post.
>> > To unsubscribe from this group, send email to
>> > clojure+unsubscr...@googlegroups.com
>> > For more options, visit this group at
>> > http://groups.google.com/group/clojure?hl=en
>>
>> --
>> 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 moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>>
>
>  --
> 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 moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>



-- 
*Satajanus  Nig. Ltd


*

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Looking for a better way

2010-12-16 Thread Laurent PETIT
Indeed !

I was stuck in the macro thinking, thanks for getting us out of it !

And then this solution not only works for literal strings:

user=> (foo (str "yo" "man"))
#'user/yoman
user=> yoman
"yoman"
user=>

2010/12/16 Robert McIntyre 

> no need to use macros at all:
>
> (defn foo
>  "creates a symbol named s with the value s in the current namespace "
>  [s]
> (intern *ns* (symbol s) s))
>
> that is, assuming I got the use case right.
>
> --Robert McIntyre
>
>
> On Wed, Dec 15, 2010 at 8:00 AM, Laurent PETIT 
> wrote:
> > 2010/12/15 Emeka 
> >>
> >> Helllo All,
> >> Is there a better way of doing this?
> >> (defmacro foo [string] (let[b# string f# (symbol b#)] `(def ~f#  ~b#)))
> >
> > Hello,
> >
> > What is it supposed to be used ?
> >
> > What do you expect the macroexpansion to look like ?
> >
> > As is stands, your example can go without the ending #'s since they
> aren't
> > declared inside the returned quoted expr. They're useless.
> >
> > So having
> >
> > (defmacro foo [string] (let [b string f (symbol string)] `(def ~f ~b)))
> >
> > But now, string is not (as you may think) evaluated within the let in the
> > macro. string is just an immutable datastructure containing "as is" what
> has
> > been passed to foo. So if what you pass to foo is something which
> > "evaluates" to a string, for example a string concatenation expression as
> > (str "the-" "value"), then the code will not do what it suggests it's
> doing
> > :
> >
> > user=> (defmacro foo [string] (let[b# string f# (symbol b#)] `(def ~f#
> > ~b#)))
> > #'user/foo
> > user=> (foo (str "the-" "value"))
> > java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast
> to
> > java.lang.String (NO_SOURCE_FILE:0)
> > user=> (macroexpand '(foo (str "the-" "value")))
> > java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast
> to
> > java.lang.String (NO_SOURCE_FILE:0)
> > user=>
> >
> >
> > Now, if you just want the macro to take literal strings as input, then
> the
> > code can be further simplified to :
> >
> > (defmacro foo [string] `(def ~(symbol string) ~string))
> >
> > user=> (defmacro foo [string] `(def ~(symbol string) ~string))
> > #'user/foo
> > user=> (foo "the-string")
> > #'user/the-string
> > user=> the-string
> > "the-string"
> > user=> (macroexpand '(foo "the-string"))
> > (def the-string "the-string")
> > user=>
> >
> > HTH,
> >
> > --
> > Laurent
> >
> > --
> > 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 moderated - please be patient with
> your
> > first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
>
> --
> 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 moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Looking for a better way

2010-12-15 Thread Robert McIntyre
no need to use macros at all:

(defn foo
 "creates a symbol named s with the value s in the current namespace "
 [s]
(intern *ns* (symbol s) s))

that is, assuming I got the use case right.

--Robert McIntyre


On Wed, Dec 15, 2010 at 8:00 AM, Laurent PETIT  wrote:
> 2010/12/15 Emeka 
>>
>> Helllo All,
>> Is there a better way of doing this?
>> (defmacro foo [string] (let[b# string f# (symbol b#)] `(def ~f#  ~b#)))
>
> Hello,
>
> What is it supposed to be used ?
>
> What do you expect the macroexpansion to look like ?
>
> As is stands, your example can go without the ending #'s since they aren't
> declared inside the returned quoted expr. They're useless.
>
> So having
>
> (defmacro foo [string] (let [b string f (symbol string)] `(def ~f ~b)))
>
> But now, string is not (as you may think) evaluated within the let in the
> macro. string is just an immutable datastructure containing "as is" what has
> been passed to foo. So if what you pass to foo is something which
> "evaluates" to a string, for example a string concatenation expression as
> (str "the-" "value"), then the code will not do what it suggests it's doing
> :
>
> user=> (defmacro foo [string] (let[b# string f# (symbol b#)] `(def ~f#
> ~b#)))
> #'user/foo
> user=> (foo (str "the-" "value"))
> java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to
> java.lang.String (NO_SOURCE_FILE:0)
> user=> (macroexpand '(foo (str "the-" "value")))
> java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to
> java.lang.String (NO_SOURCE_FILE:0)
> user=>
>
>
> Now, if you just want the macro to take literal strings as input, then the
> code can be further simplified to :
>
> (defmacro foo [string] `(def ~(symbol string) ~string))
>
> user=> (defmacro foo [string] `(def ~(symbol string) ~string))
> #'user/foo
> user=> (foo "the-string")
> #'user/the-string
> user=> the-string
> "the-string"
> user=> (macroexpand '(foo "the-string"))
> (def the-string "the-string")
> user=>
>
> HTH,
>
> --
> Laurent
>
> --
> 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 moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Looking for a better way

2010-12-15 Thread Laurent PETIT
2010/12/15 Emeka 

> *Helllo All,*
> *
> *
> *Is there a better way of doing this?*
> *
> *
> *(defmacro foo [string] (let[b# string f# (symbol b#)] `(def ~f#  ~b#)))*
>

Hello,

What is it supposed to be used ?

What do you expect the macroexpansion to look like ?

As is stands, your example can go without the ending #'s since they aren't
declared inside the returned quoted expr. They're useless.

So having

(defmacro foo [string] (let [b string f (symbol string)] `(def ~f ~b)))

But now, string is not (as you may think) evaluated within the let in the
macro. string is just an immutable datastructure containing "as is" what has
been passed to foo. So if what you pass to foo is something which
"evaluates" to a string, for example a string concatenation expression as
(str "the-" "value"), then the code will not do what it suggests it's doing
:

user=> (defmacro foo [string] (let[b# string f# (symbol b#)] `(def ~f#
~b#)))
#'user/foo
user=> (foo (str "the-" "value"))
java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to
java.lang.String (NO_SOURCE_FILE:0)
user=> (macroexpand '(foo (str "the-" "value")))
java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to
java.lang.String (NO_SOURCE_FILE:0)
user=>


Now, if you just want the macro to take literal strings as input, then the
code can be further simplified to :

(defmacro foo [string] `(def ~(symbol string) ~string))

user=> (defmacro foo [string] `(def ~(symbol string) ~string))
#'user/foo
user=> (foo "the-string")
#'user/the-string
user=> the-string
"the-string"
user=> (macroexpand '(foo "the-string"))
(def the-string "the-string")
user=>

HTH,

-- 
Laurent

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Looking for a better way

2010-12-15 Thread Emeka
*Helllo All,*
*
*
*Is there a better way of doing this?*
*
*
*(defmacro foo [string] (let[b# string f# (symbol b#)] `(def ~f#  ~b#)))*
*
*
*
*
*Regards,*
*Emeka
*

-- 
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 moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en