Re: go local variable binding

2017-03-16 Thread Timothy Baldridge
Yes, dynamic vars do not exist in CLJS, so naturally binding doesn't work
as you would expect.

On Thu, Mar 16, 2017 at 11:36 AM, Christian Weilbach <
whitesp...@polyc0l0r.net> wrote:

> You cannot do so in cljs though:
> http://dev.clojure.org/jira/browse/CLJS-1634
>
> Just in case you expect to write cross-platform code with dynamic bindings.
>
>
> Am 16.03.2017 um 01:01 schrieb Timothy Baldridge:
> > Yes, that should work fine, do your tests confirm otherwise? Also if
> > you're not doing a recur there's no reason to use `go-loop` you can just
> > use `go`.
> >
> > On Wed, Mar 15, 2017 at 4:44 PM, Eran Levi  > > wrote:
> >
> > Hi,
> > can I bind variables, same as I do for threads, for go routines, to
> > be local only for a particular go routine, and if I can't, how would
> > you mimic this behavior ?
> >
> > |
> > (defn print-stuff [s]
> >   (println s))
> >
> > (go-loop []
> >(binding [*out*(clojure.java.io/writer "foo.txt")]
> >   (print-stuff)))
> >
> > (go-loop []
> >(binding [*out*(clojure.java.io/writer "bar.txt")]
> >   (print-stuff)))
> > |
> >
> >
> > --
> > 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 unsubscribe from this group and stop receiving emails from it,
> > send an email to clojure+unsubscr...@googlegroups.com
> > .
> > For more options, visit https://groups.google.com/d/optout
> > .
> >
> >
> >
> >
> > --
> > “One of the main causes of the fall of the Roman Empire was that–lacking
> > zero–they had no way to indicate successful termination of their C
> > programs.”
> > (Robert Firth)
> >
> > --
> > 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 unsubscribe from this group and stop receiving emails from it, send
> > an email to clojure+unsubscr...@googlegroups.com
> > .
> > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: go local variable binding

2017-03-16 Thread Christian Weilbach
You cannot do so in cljs though:
http://dev.clojure.org/jira/browse/CLJS-1634

Just in case you expect to write cross-platform code with dynamic bindings.


Am 16.03.2017 um 01:01 schrieb Timothy Baldridge:
> Yes, that should work fine, do your tests confirm otherwise? Also if
> you're not doing a recur there's no reason to use `go-loop` you can just
> use `go`.
> 
> On Wed, Mar 15, 2017 at 4:44 PM, Eran Levi  > wrote:
> 
> Hi,
> can I bind variables, same as I do for threads, for go routines, to
> be local only for a particular go routine, and if I can't, how would
> you mimic this behavior ?
> 
> |
> (defn print-stuff [s]
>   (println s))
> 
> (go-loop []
>(binding [*out*(clojure.java.io/writer "foo.txt")]
>   (print-stuff)))
> 
> (go-loop []
>(binding [*out*(clojure.java.io/writer "bar.txt")]
>   (print-stuff)))
> |
> 
> 
> -- 
> 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 unsubscribe from this group and stop receiving emails from it,
> send an email to clojure+unsubscr...@googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout
> .
> 
> 
> 
> 
> -- 
> “One of the main causes of the fall of the Roman Empire was that–lacking
> zero–they had no way to indicate successful termination of their C
> programs.”
> (Robert Firth)
> 
> -- 
> 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 unsubscribe from this group and stop receiving emails from it, send
> an email to clojure+unsubscr...@googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: go local variable binding

2017-03-15 Thread Timothy Baldridge
Yes, that should work fine, do your tests confirm otherwise? Also if you're
not doing a recur there's no reason to use `go-loop` you can just use `go`.

On Wed, Mar 15, 2017 at 4:44 PM, Eran Levi  wrote:

> Hi,
> can I bind variables, same as I do for threads, for go routines, to be
> local only for a particular go routine, and if I can't, how would you mimic
> this behavior ?
>
> (defn print-stuff [s]
>   (println s))
>
> (go-loop []
>(binding [*out* (clojure.java.io/writer "foo.txt")]
>   (print-stuff)))
>
> (go-loop []
>(binding [*out* (clojure.java.io/writer "bar.txt")]
>   (print-stuff)))
>
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


go local variable binding

2017-03-15 Thread Eran Levi
Hi,
can I bind variables, same as I do for threads, for go routines, to be 
local only for a particular go routine, and if I can't, how would you mimic 
this behavior ?

(defn print-stuff [s]
  (println s))

(go-loop []
   (binding [*out* (clojure.java.io/writer "foo.txt")]
  (print-stuff)))

(go-loop []
   (binding [*out* (clojure.java.io/writer "bar.txt")]
  (print-stuff)))


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Locking non-local variable inside macro

2015-11-16 Thread Alex Miller
Usually it's better to create a sentinel (Object.) to lock on to avoid sharing 
it. (Well really it's best to avoid locking at all and use Clojure state 
constructs if you can.)

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Locking non-local variable inside macro

2015-11-15 Thread Michael Blume
The problem here is that you are splicing in obj when there is no need to.
You actually want your generated code to refer to obj. So just

(defmacro mac1 [& body] `(locking obj ~@body))

is fine.

dennis' solution will work too, but it will work almost accidentally? All
blank maps evaluate to the same object, so if you do (locking {}
(whatever)) it will lock on the same map every time, but if for some reason
someone else does the same trick, you'll be competing for the same lock.
Better to do what you're doing, but without the unnecessary splice.

On Sun, Nov 15, 2015 at 11:17 PM dennis zhuang  wrote:

> I think the reason is in macroexpand-1 result:
>
> user=> (macroexpand-1 '(mac1 1))
> (clojure.core/locking # 1)
>
> It's not a valid form to be read and eval by clojure reader,the object
> form can't be parsed.
>
> If define obj to be a map {}, it works fine:
>
> user=> (def obj {})
> #'user/obj
> user=> (mac1 1)
> 1
> user=> (macroexpand-1 '(mac1 1))
> (clojure.core/locking {} 1)
>
>
> 2015-11-16 13:55 GMT+08:00 Alice :
>
>> user=> (def obj (Object.))
>> #'user/obj
>> user=> (defmacro mac1 [& body] `(locking ~obj ~@body))
>> #'user/mac1
>> user=> (mac1 nil)
>> CompilerException java.lang.RuntimeException: Can't embed object in code,
>> maybe print-dup not defined: java.lang.Object@2a747a37,
>> compiling:(NO_SOURCE_PATH:1:1)
>>
>>
>> Why am I getting the error?
>>
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> 庄晓丹
> Email:killme2...@gmail.com xzhu...@avos.com
> Site:   http://fnil.net
> Twitter:  @killme2008
>
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Locking non-local variable inside macro

2015-11-15 Thread dennis zhuang
I think the reason is in macroexpand-1 result:

user=> (macroexpand-1 '(mac1 1))
(clojure.core/locking # 1)

It's not a valid form to be read and eval by clojure reader,the object form
can't be parsed.

If define obj to be a map {}, it works fine:

user=> (def obj {})
#'user/obj
user=> (mac1 1)
1
user=> (macroexpand-1 '(mac1 1))
(clojure.core/locking {} 1)


2015-11-16 13:55 GMT+08:00 Alice :

> user=> (def obj (Object.))
> #'user/obj
> user=> (defmacro mac1 [& body] `(locking ~obj ~@body))
> #'user/mac1
> user=> (mac1 nil)
> CompilerException java.lang.RuntimeException: Can't embed object in code,
> maybe print-dup not defined: java.lang.Object@2a747a37,
> compiling:(NO_SOURCE_PATH:1:1)
>
>
> Why am I getting the error?
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
庄晓丹
Email:killme2...@gmail.com xzhu...@avos.com
Site:   http://fnil.net
Twitter:  @killme2008

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Locking non-local variable inside macro

2015-11-15 Thread Alice
user=> (def obj (Object.))
#'user/obj
user=> (defmacro mac1 [& body] `(locking ~obj ~@body))
#'user/mac1
user=> (mac1 nil)
CompilerException java.lang.RuntimeException: Can't embed object in code, 
maybe print-dup not defined: java.lang.Object@2a747a37, 
compiling:(NO_SOURCE_PATH:1:1)


Why am I getting the error?

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-09 Thread Cecil Westerhof
2014-07-09 4:19 GMT+02:00 Bob Hutchison :

>
> On Jul 8, 2014, at 7:08 PM, Cecil Westerhof 
> wrote:
>
> 2014-07-08 23:11 GMT+02:00 Bob Hutchison :
>
>>
>> On Jul 8, 2014, at 9:40 AM, Cecil Westerhof 
>> wrote:
>>
>> > In Clojure you can define a local constant with let, but I need a
>> variable (I think).
>> >
>> > I want to do the following. I have a function that checks several
>> things. Every time an error is found I want to set the variable errors to:
>> > (concat errors new-error)
>> >
>> > Is this possible? Or is there a better way to do this?
>>
>> Here's a different take on your question, and a few comments about how
>> I'd write that code. I don't think you need the atom -- kinda ugly and the
>> reduce/map/filter family of sequence functions will take you a long way.
>>
>> ; This is not a predicate, so don't use the -p suffix (and in Clojure
>> it's a ? normally)
>>
>
> ​As I understood it (I am rewriting land of lisp to Clojure) that when a
> function returns a true/false state, that you then use the -p suffix. When
> returning () there are no errors. But I should use the ? then?
>
>
> You’re returning a list of errors. You can interpret that as a
> truthy/falsy kind of thing, in which case make sure you’re returning a nil
> for the no-error case. And use the ‘?’ in Clojure.
>

​That I do with:
(let [errors (atom ())]

I changed the name to 'error-in-datastruct?'.


By the way. The current function is only the start of the checks.​
>
> ​After the if I need to do several other checks also. So I think I do need
> the atom. But maybe I am mistaken. ;-)
>
>
> I thought maybe your checks would be a little more than that. That’s why I
> left the ‘reduce’ version in there. Just make the function that is applied
> by reduce more powerful, perhaps pull it out into a separate function
> rather than an inline anonymous function. This will work as long as all
> tests are performed on one object at a time.
>
> No matter what, I’d recommend not going using an atom if you can help it.
>

​I have my work cut out. But that is the best way to learn. :-D

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-08 Thread Bob Hutchison

On Jul 8, 2014, at 7:08 PM, Cecil Westerhof  wrote:

> 2014-07-08 23:11 GMT+02:00 Bob Hutchison :
> 
> On Jul 8, 2014, at 9:40 AM, Cecil Westerhof  wrote:
> 
> > In Clojure you can define a local constant with let, but I need a variable 
> > (I think).
> >
> > I want to do the following. I have a function that checks several things. 
> > Every time an error is found I want to set the variable errors to:
> > (concat errors new-error)
> >
> > Is this possible? Or is there a better way to do this?
> 
> Here's a different take on your question, and a few comments about how I'd 
> write that code. I don't think you need the atom -- kinda ugly and the 
> reduce/map/filter family of sequence functions will take you a long way.
> 
> ; This is not a predicate, so don't use the -p suffix (and in Clojure it's a 
> ? normally)
> 
> ​As I understood it (I am rewriting land of lisp to Clojure) that when a 
> function returns a true/false state, that you then use the -p suffix. When 
> returning () there are no errors. But I should use the ? then?

You’re returning a list of errors. You can interpret that as a truthy/falsy 
kind of thing, in which case make sure you’re returning a nil for the no-error 
case. And use the ‘?’ in Clojure.

> 
> ​ 
> ; There's no reason not to pass those two objects into this function, so I do.
> 
> ​Good idea. Makes it easy to test the function also.

it does

> 
> […]​ 
>  
> I hope you can make sense of that :-)
> 
> ​Not immediately. I need to digest it.

Have fun.

> 
> By the way. The current function is only the start of the checks.​  ​After 
> the if I need to do several other checks also. So I think I do need the atom. 
> But maybe I am mistaken. ;-)

I thought maybe your checks would be a little more than that. That’s why I left 
the ‘reduce’ version in there. Just make the function that is applied by reduce 
more powerful, perhaps pull it out into a separate function rather than an 
inline anonymous function. This will work as long as all tests are performed on 
one object at a time.

No matter what, I’d recommend not going using an atom if you can help it.

Cheers,
Bob

> 
> -- 
> Cecil Westerhof
> 
> -- 
> 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 unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-08 Thread Cecil Westerhof
2014-07-08 23:11 GMT+02:00 Bob Hutchison :

>
> On Jul 8, 2014, at 9:40 AM, Cecil Westerhof 
> wrote:
>
> > In Clojure you can define a local constant with let, but I need a
> variable (I think).
> >
> > I want to do the following. I have a function that checks several
> things. Every time an error is found I want to set the variable errors to:
> > (concat errors new-error)
> >
> > Is this possible? Or is there a better way to do this?
>
> Here's a different take on your question, and a few comments about how I'd
> write that code. I don't think you need the atom -- kinda ugly and the
> reduce/map/filter family of sequence functions will take you a long way.
>
> ; This is not a predicate, so don't use the -p suffix (and in Clojure it's
> a ? normally)
>

​As I understood it (I am rewriting land of lisp to Clojure) that when a
function returns a true/false state, that you then use the -p suffix. When
returning () there are no errors. But I should use the ? then?

​


> ; There's no reason not to pass those two objects into this function, so I
> do.
>

​Good idea. Makes it easy to test the function also.

[…]​



> I hope you can make sense of that :-)
>

​Not immediately. I need to digest it.

By the way. The current function is only the start of the checks.​

​After the if I need to do several other checks also. So I think I do need
the atom. But maybe I am mistaken. ;-)

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-08 Thread Bob Hutchison

On Jul 8, 2014, at 9:40 AM, Cecil Westerhof  wrote:

> In Clojure you can define a local constant with let, but I need a variable (I 
> think).
> 
> I want to do the following. I have a function that checks several things. 
> Every time an error is found I want to set the variable errors to:
> (concat errors new-error)
> 
> Is this possible? Or is there a better way to do this?

Here's a different take on your question, and a few comments about how I'd 
write that code. I don't think you need the atom -- kinda ugly and the 
reduce/map/filter family of sequence functions will take you a long way.

; This is not a predicate, so don't use the -p suffix (and in Clojure it's a ? 
normally)
; There's no reason not to pass those two objects into this function, so I do.
(defn errors-in-datastruct [locations objects]
  (if (= (count objects) (count locations))
; 'remove' makes a new sequence containing elements that had a falsey 
; (false or nil) result to the provided function -- that is the objects
; with no location

; the mapv maps a function over a sequence resulting in a vector.
; the function creates a vector pair for each object containing the error
; code and object

; I find vectors more natural to use in Clojure

; I also find keywords more natural (and useful)

; In my mind, finding the errors and reporting them are two separate 
functions. If you want to make
; a nicer error report, then map a reporting function over the error codes.

(mapv #(vector :no-location %) (remove locations objects))

; This reduce does something similar to the mapv/remove combination above, 
but 
; it gives you more flexibility.

#_(reduce (fn [errors obj] 
(if (locations obj) 
  errors 
  (conj errors [:no-location obj]))) [] objects)

[[:counts-differ]]))

; use locally scoped variables if you can
(let [locations {:whiskey :living-room
 :bucket  :living-room
 :chain   :garden
 :frog:garden
 :dummy   :nowhere}]
  (println (errors-in-datastruct locations [:whiskey :bucket :chain :frog 
:dummy]))
  (println (errors-in-datastruct locations [:whiskey :bucket :chain :frog :pole 
:dummy]))
  (println (errors-in-datastruct locations [:whiskey :bucket :chain :frog 
:pole]))
  (println (errors-in-datastruct locations [:whiskey :bucket :chain :frog1 
:pole]))
  (println (errors-in-datastruct locations [:whiskey :whiskey :whiskey :whiskey 
:whiskey])))


; If you need to use the same locations map and don't want to pass it around, 
you can
; partially apply the errors-in-datastruct function to the locations, and use 
that function.
; You probably don't care about this but the technique can be very handy when 
getting
; rid of global variables.
(let [f (partial errors-in-datastruct {:whiskey :living-room
   :bucket  :living-room
   :chain   :garden
   :frog:garden
   :dummy   :nowhere})]
  (println (f [:whiskey :bucket :chain :frog :dummy]))
  (println (f [:whiskey :bucket :chain :frog :pole :dummy]))
  (println (f [:whiskey :bucket :chain :frog :pole]))
  (println (f [:whiskey :bucket :chain :frog1 :pole])))


I hope you can make sense of that :-)

Cheers,
Bob

> 
> -- 
> Cecil Westerhof
> 
> -- 
> 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 unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-08 Thread blake
>
> Also, just a matter of style, but it's customary to leave closing parens
>> at the end of a line, rather than by themselves on their own line.
>>
>
> ​I do that also, but when I am editing I put them on there own line,
> because in this way changes are faster. When I am satisfied, I merge them.
> ;-)
>
>
I also tend to not stack them like that till I'm done futzing. Pretty sure
it's a sign of noobiness. =P

When I see others code, they're perfectly capable of using the editor to
slide the expressions around so that it doesn't matter if the parens are at
the end of the line. (Learning to do that is next on my to-do list.)

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-08 Thread Cecil Westerhof
2014-07-08 18:14 GMT+02:00 John Gabriele :

> On Tuesday, July 8, 2014 11:38:42 AM UTC-4, Cecil Westerhof wrote:
>>
>>
>>
>>
>> 2014-07-08 16:55 GMT+02:00 John Gabriele :
>>
>> On Tuesday, July 8, 2014 9:40:54 AM UTC-4, Cecil Westerhof wrote:

 In Clojure you can define a local constant with let, but I need a
 variable (I think).

 I want to do the following. I have a function that checks several
 things. Every time an error is found I want to set the variable errors to:
 (concat errors new-error)

 Is this possible? Or is there a better way to do this?


>>> You *could* do something like:
>>>
>>> ~~~
>>> (let [errors  (atom [])
>>>   ...
>>>   (swap! errors conj "error-X")
>>>   ...)
>>> ~~~
>>>
>>
>> ​I al-ready tried something along those lines:​
>> (defn error-in-datastruct-p []
>>   (let [errors (atom ())]
>>(if (= (count objects) (count *object-locations*))
>>(map (fn [x]
>> (println x)
>> (if (not (*object-locations* x))
>> (do
>> (println x)
>> (swap! errors conj (remove-symbol-from-output
>> `(No location for ~x)))
>> @errors
>> )
>>   ))
>> objects)
>>  (swap! errors conj '(Number of objects and number of object
>> locations is not the same.)))
>>@errors))
>>
>>
> `map` is for creating seqs (and lazy ones at that); it's not for
> side-effects. If you want side-effects, try `doseq`.
>

​That was the problem. I know have:
(defn error-in-datastruct-p []
  (let [errors (atom ())]
   (if (= (count objects) (count *object-locations*))
   (doseq [obj objects]
  (if (not (*object-locations* obj))
  (swap! errors conj (remove-symbol-from-output `(No
location for ~obj)
 (swap! errors conj '(Number of objects and number of object
locations is not the same.)))
   (reverse @errors)))

And that works.

​


> Also, just a matter of style, but it's customary to leave closing parens
> at the end of a line, rather than by themselves on their own line.
>

​I do that also, but when I am editing I put them on there own line,
because in this way changes are faster. When I am satisfied, I merge them.
;-)


By the way I would like to put a point after the message, like:
(swap! errors conj (remove-symbol-from-output `(No location for
~obj.)
​

​But that gives:
CompilerException java.lang.ClassNotFoundException: obj.,
compiling:(NO_SOURCE_PATH:124:42)

Is there a way to get the point behind the line?​

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-08 Thread John Gabriele
On Tuesday, July 8, 2014 11:38:42 AM UTC-4, Cecil Westerhof wrote:
>
>
>
>
> 2014-07-08 16:55 GMT+02:00 John Gabriele >:
>
>> On Tuesday, July 8, 2014 9:40:54 AM UTC-4, Cecil Westerhof wrote:
>>>
>>> In Clojure you can define a local constant with let, but I need a 
>>> variable (I think).
>>>
>>> I want to do the following. I have a function that checks several 
>>> things. Every time an error is found I want to set the variable errors to:
>>> (concat errors new-error)
>>>
>>> Is this possible? Or is there a better way to do this?
>>>
>>>
>> You *could* do something like:
>>
>> ~~~
>> (let [errors  (atom [])
>>   ...
>>   (swap! errors conj "error-X")
>>   ...)
>> ~~~
>>
>
> ​I al-ready tried something along those lines:​
> (defn error-in-datastruct-p []
>   (let [errors (atom ())]
>(if (= (count objects) (count *object-locations*))
>(map (fn [x]
> (println x)
> (if (not (*object-locations* x))
> (do
> (println x)
> (swap! errors conj (remove-symbol-from-output 
> `(No location for ~x)))
> @errors
> )
>   ))
> objects)
>  (swap! errors conj '(Number of objects and number of object 
> locations is not the same.)))
>@errors))
>
>
`map` is for creating seqs (and lazy ones at that); it's not for 
side-effects. If you want side-effects, try `doseq`.

Also, just a matter of style, but it's customary to leave closing parens at 
the end of a line, rather than by themselves on their own line.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-08 Thread Lars Nilsson
On Tue, Jul 8, 2014 at 11:38 AM, Cecil Westerhof  wrote:
> I al-ready tried something along those lines:
> (defn error-in-datastruct-p []
>   (let [errors (atom ())]
>(if (= (count objects) (count *object-locations*))
>(map (fn [x]
> (println x)
> (if (not (*object-locations* x))
> (do
> (println x)
> (swap! errors conj (remove-symbol-from-output
> `(No location for ~x)))
> @errors
> )
>   ))
> objects)
>  (swap! errors conj '(Number of objects and number of object
> locations is not the same.)))
>@errors))
>
> (error-in-datastruct-p)
>
> This gives:
> user=> user=> ()
>
> When I only remove the last @errors, I get:
> user=> user=> (whiskey
> bucket
> nil chain
> nil frog
> nil pole
> pole
> nil ((No location for pole)))
>
>
> What could be happening here?

You're discarding the result of the (if ...) because it is directly
followed by @errors and as a result the lazy evaluation of (map ...)
is not happening, and your println and errors updates does not get
executed.

Lars Nilsson

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-08 Thread Cecil Westerhof
2014-07-08 16:55 GMT+02:00 John Gabriele :

> On Tuesday, July 8, 2014 9:40:54 AM UTC-4, Cecil Westerhof wrote:
>>
>> In Clojure you can define a local constant with let, but I need a
>> variable (I think).
>>
>> I want to do the following. I have a function that checks several things.
>> Every time an error is found I want to set the variable errors to:
>> (concat errors new-error)
>>
>> Is this possible? Or is there a better way to do this?
>>
>>
> You *could* do something like:
>
> ~~~
> (let [errors  (atom [])
>   ...
>   (swap! errors conj "error-X")
>   ...)
> ~~~
>

​I al-ready tried something along those lines:​
(defn error-in-datastruct-p []
  (let [errors (atom ())]
   (if (= (count objects) (count *object-locations*))
   (map (fn [x]
(println x)
(if (not (*object-locations* x))
(do
(println x)
(swap! errors conj (remove-symbol-from-output
`(No location for ~x)))
@errors
)
  ))
objects)
 (swap! errors conj '(Number of objects and number of object
locations is not the same.)))
   @errors))

(error-in-datastruct-p)

This gives:
user=> user=> ()

When I only remove the last @errors, I get:
user=> user=> (whiskey
bucket
nil chain
nil frog
nil pole
pole
nil ((No location for pole)))


What could be happening here?

The variables are defined with:
(def objects '(whiskey bucket chain frog pole))

(def ^:dynamic *object-locations* {
 'whiskey   'living-room
 'bucket'living-room
 'chain 'garden
 'frog  'garden
 'dummy 'nowhere
 })

And I am using clojure 1.6.0.


​By the way when changing *object-locations* to:​
​(def ^:dynamic *object-locations* {
 'whiskey   'living-room
 'bucket'living-room
 'chain 'garden
 'frog  'garden
 })

​There is no problem, then I get the expected:
user=> user=> ((Number of objects and number of object locations is not the
same.))


-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-08 Thread John Gabriele
On Tuesday, July 8, 2014 9:40:54 AM UTC-4, Cecil Westerhof wrote:
>
> In Clojure you can define a local constant with let, but I need a variable 
> (I think).
>
> I want to do the following. I have a function that checks several things. 
> Every time an error is found I want to set the variable errors to:
> (concat errors new-error)
>
> Is this possible? Or is there a better way to do this?
>
>
You *could* do something like:

~~~
(let [errors  (atom [])
  ...
  (swap! errors conj "error-X")
  ...)
~~~

though, a more functional approach might look more like:

~~~
(loop [errors []
   things-to-check ...]
  (if (empty? things-to-check)
errors
(recur (conj errors (check (first things-to-check)))
   (rest things-to-check
~~~

-- John

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-08 Thread Ashish Negi
you can make that variable "error" as an Agent and change it asynchronously 
or as a Ref if you want the change synchronously. other part of the code 
remains same.

On Tuesday, 8 July 2014 19:10:54 UTC+5:30, Cecil Westerhof wrote:
>
> In Clojure you can define a local constant with let, but I need a variable 
> (I think).
>
> I want to do the following. I have a function that checks several things. 
> Every time an error is found I want to set the variable errors to:
> (concat errors new-error)
>
> Is this possible? Or is there a better way to do this?
>
> -- 
> Cecil Westerhof 
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Local variable

2014-07-08 Thread Michael Klishin
 On 8 July 2014 at 17:40:49, Cecil Westerhof (cldwester...@gmail.com) wrote:
> > In Clojure you can define a local constant with let, but I need  
> a variable (I think).

They are not constants. Locals can be "overwritten" but their data structures
are immutable (by default).

> I want to do the following. I have a function that checks several  
> things. Every time an error is found I want to set the variable  
> errors to:
> (concat errors new-error)
>  
> Is this possible? Or is there a better way to do this?

You can do that with loop/recur or an atom. The key is to understand
that in Clojure, values and references are separate, and references
can be mutated but in a particular, concurrency-aware way:

http://clojure-doc.org/articles/language/concurrency_and_parallelism.html#identity/value-separation-("on-state-and-identity")
--  
MK

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Local variable

2014-07-08 Thread Cecil Westerhof
In Clojure you can define a local constant with let, but I need a variable
(I think).

I want to do the following. I have a function that checks several things.
Every time an error is found I want to set the variable errors to:
(concat errors new-error)

Is this possible? Or is there a better way to do this?

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Filling let local variable from sequence

2011-06-30 Thread octopusgrabbus
Phew! Thank you. That did it. I did need to add the nil to each nth
statement, but this helps.

(defn process-file
  "Process csv file and prints a column in every row"
  [file-name]
  (let [data (slurp file-name)
rows (parse-csv data)
read-map (zipmap (map #(nth % 11 nil) rows) (map #(nth % 1
nil) rows))]
(println read-map)))



On Jun 30, 4:48 pm, Ken Wesson  wrote:
> On Thu, Jun 30, 2011 at 4:30 PM, octopusgrabbus
>
>
>
>
>
>
>
>
>
>  wrote:
> > Thanks for answering.
>
> > I want to create a map of this output:
>
> > PremiseID Reading
> > 61016 101100
> > 610159000 411200
> > 610158000 133100
> > 610157000 239400
> > nil nil
>
> > produced by this function
>
> > (defn process-file
> >  "Process csv file and prints a column in every row"
> >  [file-name]
> >  (let [data (slurp file-name)
> >        rows (parse-csv data)]
> >        (doseq [this-row rows] (println (nth this-row 11 nil) (nth
> > this-row 1 nil)
>
> > from this data:
>
> > "MeterID","Reading","ReadingDateTime","Account","CustomerLN","CustomerFN","DeviceID","DeviceType","ChannelNumber","DecodeType","LoadDateLocal","PremiseID"
> > 33891715,101100,"2011-06-05 23:00:00","61016","SMITH","E & J",
> > 80581200,43,0,75,"2011-06-06 06:00:01","61016"
> > 33891773,411200,"2011-06-05 23:00:00","610159000","COMMONER","A",
> > 80598726,43,0,75,"2011-06-06 06:00:01","610159000"
> > 33891887,133100,"2011-06-05 23:00:00","610158000","JONES","J & M",
> > 80581189,43,0,75,"2011-06-06 06:00:01","610158000"
> > 33891825,239400,"2011-06-05 23:00:00","610157000","SAWTOOTH","GEORGE
> > C",80598731,43,0,75,"2011-06-06 06:00:01","610157000"
>
> Then you want (zipmap (map #(nth % 11) rows) (map #(nth % 1) rows)).
>
> --
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.

-- 
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: Filling let local variable from sequence

2011-06-30 Thread octopusgrabbus
I need to clarify my previous answer.

In each row of vectors I want to extract two columns and make a map of
those.

For example, for each premiseid, there is a reading.

So for this line of data

33891715,101100,"2011-06-05 23:00:00","61016","SMITH","E & J",
80581200,43,0,75,"2011-06-06 06:00:01","61016"

I want to map the premise id "61016" to the reading 101100.



On Jun 30, 4:24 pm, Ken Wesson  wrote:
> On Thu, Jun 30, 2011 at 4:15 PM, octopusgrabbus
>
>
>
>
>
>
>
>
>
>  wrote:
> > The dorun in this function
>
> > (defn process-file
> >  "Process csv file and prints first item in every row"
> >  [file-name]
> >  (let [data (slurp file-name)
> >        rows (parse-csv data)]
> >    (dorun (map #(println (first %)) rows
>
> > causes each row of vectors in rows to be processed.
>
> > (doseq [a-row rows] (println a-row) )
>
> > would print each row in the data, which looks like this (the real
> > data, not the test data I've been using today.)
>
> > "MeterID","Reading","ReadingDateTime","Account","CustomerLN","CustomerFN","DeviceID","DeviceType","ChannelNumber","DecodeType","LoadDateLocal","PremiseID"
> > 33891715,101100,"2011-06-05 23:00:00","61016","SMITH","E & J",
> > 80581200,43,0,75,"2011-06-06 06:00:01","61016"
> > 33891773,411200,"2011-06-05 23:00:00","610159000","COMMONER","A",
> > 80598726,43,0,75,"2011-06-06 06:00:01","610159000"
> > 33891887,133100,"2011-06-05 23:00:00","610158000","JONES","J & M",
> > 80581189,43,0,75,"2011-06-06 06:00:01","610158000"
> > 33891825,239400,"2011-06-05 23:00:00","610157000","SAWTOOTH","GEORGE
> > C",80598731,43,0,75,"2011-06-06 06:00:01","610157000"
>
> > It would be nice if the let statement would allow populating a local
> > variable from iterating all the rows of vectors. I just can't figure
> > out how to do it.
>
> So you just want a variable bound to a flat list of the things in the
> vectors, or of the vectors themselves?
>
> (let [x seq-of-vectors])
>
> will accomplish the latter, and
>
> (let [x (apply concat seq-of-vectors)])
>
> the former.
>
> --
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.

-- 
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: Filling let local variable from sequence

2011-06-30 Thread Ken Wesson
On Thu, Jun 30, 2011 at 4:30 PM, octopusgrabbus
 wrote:
> Thanks for answering.
>
> I want to create a map of this output:
>
> PremiseID Reading
> 61016 101100
> 610159000 411200
> 610158000 133100
> 610157000 239400
> nil nil
>
> produced by this function
>
> (defn process-file
>  "Process csv file and prints a column in every row"
>  [file-name]
>  (let [data (slurp file-name)
>        rows (parse-csv data)]
>        (doseq [this-row rows] (println (nth this-row 11 nil) (nth
> this-row 1 nil)
>
> from this data:
>
> "MeterID","Reading","ReadingDateTime","Account","CustomerLN","CustomerFN","DeviceID","DeviceType","ChannelNumber","DecodeType","LoadDateLocal","PremiseID"
> 33891715,101100,"2011-06-05 23:00:00","61016","SMITH","E & J",
> 80581200,43,0,75,"2011-06-06 06:00:01","61016"
> 33891773,411200,"2011-06-05 23:00:00","610159000","COMMONER","A",
> 80598726,43,0,75,"2011-06-06 06:00:01","610159000"
> 33891887,133100,"2011-06-05 23:00:00","610158000","JONES","J & M",
> 80581189,43,0,75,"2011-06-06 06:00:01","610158000"
> 33891825,239400,"2011-06-05 23:00:00","610157000","SAWTOOTH","GEORGE
> C",80598731,43,0,75,"2011-06-06 06:00:01","610157000"

Then you want (zipmap (map #(nth % 11) rows) (map #(nth % 1) rows)).

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: Filling let local variable from sequence

2011-06-30 Thread octopusgrabbus
Thanks, Ken.
Our answers crossed. I'll go try your suggestions.

On Jun 30, 4:24 pm, Ken Wesson  wrote:
> On Thu, Jun 30, 2011 at 4:15 PM, octopusgrabbus
>
>
>
>
>
>
>
>
>
>  wrote:
> > The dorun in this function
>
> > (defn process-file
> >  "Process csv file and prints first item in every row"
> >  [file-name]
> >  (let [data (slurp file-name)
> >        rows (parse-csv data)]
> >    (dorun (map #(println (first %)) rows
>
> > causes each row of vectors in rows to be processed.
>
> > (doseq [a-row rows] (println a-row) )
>
> > would print each row in the data, which looks like this (the real
> > data, not the test data I've been using today.)
>
> > "MeterID","Reading","ReadingDateTime","Account","CustomerLN","CustomerFN","DeviceID","DeviceType","ChannelNumber","DecodeType","LoadDateLocal","PremiseID"
> > 33891715,101100,"2011-06-05 23:00:00","61016","SMITH","E & J",
> > 80581200,43,0,75,"2011-06-06 06:00:01","61016"
> > 33891773,411200,"2011-06-05 23:00:00","610159000","COMMONER","A",
> > 80598726,43,0,75,"2011-06-06 06:00:01","610159000"
> > 33891887,133100,"2011-06-05 23:00:00","610158000","JONES","J & M",
> > 80581189,43,0,75,"2011-06-06 06:00:01","610158000"
> > 33891825,239400,"2011-06-05 23:00:00","610157000","SAWTOOTH","GEORGE
> > C",80598731,43,0,75,"2011-06-06 06:00:01","610157000"
>
> > It would be nice if the let statement would allow populating a local
> > variable from iterating all the rows of vectors. I just can't figure
> > out how to do it.
>
> So you just want a variable bound to a flat list of the things in the
> vectors, or of the vectors themselves?
>
> (let [x seq-of-vectors])
>
> will accomplish the latter, and
>
> (let [x (apply concat seq-of-vectors)])
>
> the former.
>
> --
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.

-- 
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: Filling let local variable from sequence

2011-06-30 Thread octopusgrabbus
Thanks for answering.

I want to create a map of this output:

PremiseID Reading
61016 101100
610159000 411200
610158000 133100
610157000 239400
nil nil

produced by this function

(defn process-file
  "Process csv file and prints a column in every row"
  [file-name]
  (let [data (slurp file-name)
rows (parse-csv data)]
(doseq [this-row rows] (println (nth this-row 11 nil) (nth
this-row 1 nil)

from this data:

"MeterID","Reading","ReadingDateTime","Account","CustomerLN","CustomerFN","DeviceID","DeviceType","ChannelNumber","DecodeType","LoadDateLocal","PremiseID"
33891715,101100,"2011-06-05 23:00:00","61016","SMITH","E & J",
80581200,43,0,75,"2011-06-06 06:00:01","61016"
33891773,411200,"2011-06-05 23:00:00","610159000","COMMONER","A",
80598726,43,0,75,"2011-06-06 06:00:01","610159000"
33891887,133100,"2011-06-05 23:00:00","610158000","JONES","J & M",
80581189,43,0,75,"2011-06-06 06:00:01","610158000"
33891825,239400,"2011-06-05 23:00:00","610157000","SAWTOOTH","GEORGE
C",80598731,43,0,75,"2011-06-06 06:00:01","610157000"

tnx
cmn

On Jun 30, 4:24 pm, Ken Wesson  wrote:
> On Thu, Jun 30, 2011 at 4:15 PM, octopusgrabbus
>
>
>
>
>
>
>
>
>
>  wrote:
> > The dorun in this function
>
> > (defn process-file
> >  "Process csv file and prints first item in every row"
> >  [file-name]
> >  (let [data (slurp file-name)
> >        rows (parse-csv data)]
> >    (dorun (map #(println (first %)) rows
>
> > causes each row of vectors in rows to be processed.
>
> > (doseq [a-row rows] (println a-row) )
>
> > would print each row in the data, which looks like this (the real
> > data, not the test data I've been using today.)
>
> > "MeterID","Reading","ReadingDateTime","Account","CustomerLN","CustomerFN","DeviceID","DeviceType","ChannelNumber","DecodeType","LoadDateLocal","PremiseID"
> > 33891715,101100,"2011-06-05 23:00:00","61016","SMITH","E & J",
> > 80581200,43,0,75,"2011-06-06 06:00:01","61016"
> > 33891773,411200,"2011-06-05 23:00:00","610159000","COMMONER","A",
> > 80598726,43,0,75,"2011-06-06 06:00:01","610159000"
> > 33891887,133100,"2011-06-05 23:00:00","610158000","JONES","J & M",
> > 80581189,43,0,75,"2011-06-06 06:00:01","610158000"
> > 33891825,239400,"2011-06-05 23:00:00","610157000","SAWTOOTH","GEORGE
> > C",80598731,43,0,75,"2011-06-06 06:00:01","610157000"
>
> > It would be nice if the let statement would allow populating a local
> > variable from iterating all the rows of vectors. I just can't figure
> > out how to do it.
>
> So you just want a variable bound to a flat list of the things in the
> vectors, or of the vectors themselves?
>
> (let [x seq-of-vectors])
>
> will accomplish the latter, and
>
> (let [x (apply concat seq-of-vectors)])
>
> the former.
>
> --
> Protege: What is this seething mass of parentheses?!
> Master: Your father's Lisp REPL. This is the language of a true
> hacker. Not as clumsy or random as C++; a language for a more
> civilized age.

-- 
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: Filling let local variable from sequence

2011-06-30 Thread Ken Wesson
On Thu, Jun 30, 2011 at 4:15 PM, octopusgrabbus
 wrote:
> The dorun in this function
>
> (defn process-file
>  "Process csv file and prints first item in every row"
>  [file-name]
>  (let [data (slurp file-name)
>        rows (parse-csv data)]
>    (dorun (map #(println (first %)) rows
>
> causes each row of vectors in rows to be processed.
>
> (doseq [a-row rows] (println a-row) )
>
> would print each row in the data, which looks like this (the real
> data, not the test data I've been using today.)
>
> "MeterID","Reading","ReadingDateTime","Account","CustomerLN","CustomerFN","DeviceID","DeviceType","ChannelNumber","DecodeType","LoadDateLocal","PremiseID"
> 33891715,101100,"2011-06-05 23:00:00","61016","SMITH","E & J",
> 80581200,43,0,75,"2011-06-06 06:00:01","61016"
> 33891773,411200,"2011-06-05 23:00:00","610159000","COMMONER","A",
> 80598726,43,0,75,"2011-06-06 06:00:01","610159000"
> 33891887,133100,"2011-06-05 23:00:00","610158000","JONES","J & M",
> 80581189,43,0,75,"2011-06-06 06:00:01","610158000"
> 33891825,239400,"2011-06-05 23:00:00","610157000","SAWTOOTH","GEORGE
> C",80598731,43,0,75,"2011-06-06 06:00:01","610157000"
>
> It would be nice if the let statement would allow populating a local
> variable from iterating all the rows of vectors. I just can't figure
> out how to do it.

So you just want a variable bound to a flat list of the things in the
vectors, or of the vectors themselves?

(let [x seq-of-vectors])

will accomplish the latter, and

(let [x (apply concat seq-of-vectors)])

the former.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: Filling let local variable from sequence

2011-06-30 Thread octopusgrabbus
The dorun in this function

(defn process-file
  "Process csv file and prints first item in every row"
  [file-name]
  (let [data (slurp file-name)
rows (parse-csv data)]
(dorun (map #(println (first %)) rows

causes each row of vectors in rows to be processed.

(doseq [a-row rows] (println a-row) )

would print each row in the data, which looks like this (the real
data, not the test data I've been using today.)

"MeterID","Reading","ReadingDateTime","Account","CustomerLN","CustomerFN","DeviceID","DeviceType","ChannelNumber","DecodeType","LoadDateLocal","PremiseID"
33891715,101100,"2011-06-05 23:00:00","61016","SMITH","E & J",
80581200,43,0,75,"2011-06-06 06:00:01","61016"
33891773,411200,"2011-06-05 23:00:00","610159000","COMMONER","A",
80598726,43,0,75,"2011-06-06 06:00:01","610159000"
33891887,133100,"2011-06-05 23:00:00","610158000","JONES","J & M",
80581189,43,0,75,"2011-06-06 06:00:01","610158000"
33891825,239400,"2011-06-05 23:00:00","610157000","SAWTOOTH","GEORGE
C",80598731,43,0,75,"2011-06-06 06:00:01","610157000"

It would be nice if the let statement would allow populating a local
variable from iterating all the rows of vectors. I just can't figure
out how to do it.

On Jun 30, 3:28 pm, Mark Rathwell  wrote:
> Not sure what you mean by 'row of vectors', and 'break up each row'.
>
> On Thu, Jun 30, 2011 at 3:20 PM, octopusgrabbus 
> wrote:
>
>
>
>
>
>
>
> > If I have rows of vectors, such as the return from clojure-csv\parse-
> > csv
>
> > ["a" 1 "b" 2 "c" 3 "d" 4]
> > ["e" 5 "f" 6 "g" 7 "h" 8]
>
> > How can I break up each row?
>
> > I've tried doseq in the let statement, but get an error.
>
> > On Jun 30, 2:27 pm, octopusgrabbus  wrote:
> > > Thanks. That did it.
>
> > > On Jun 30, 1:22 pm, Mark Rathwell  wrote:
>
> > > > One way would be:
>
> > > > (defn map-func
> > > >    "test map function"
> > > >    []
> > > >    (let [mtr-seq (vector "a" 1 "b" 2 "c" 3 "d" 4)
> > > >          read-map (apply hash-map mtr-seq)
> > > >          (println read-map)))
>
> > > > On Thu, Jun 30, 2011 at 1:09 PM, octopusgrabbus <
> > octopusgrab...@gmail.com>wrote:
>
> > > > > Given this function
>
> > > > > (defn map-func
> > > > >    "test map function"
> > > > >    []
> > > > >    (let [mtr-seq (vector "a" 1 "b" 2 "c" 3 "d" 4)
> > > > >          read-map ()
> > > > >          (println read-map)))
>
> > > > > I want to load read-map with the keys and values from mtr-seq.
>
> > > > > Eventually, this data is going to be from the return from parse-csv
> > > > > (clojure-csv), but I seem to be making more progress using simpler
> > > > > examples.
>
> > > > > The "a", "b", and so on represent a character string premise id, and
> > > > > the 1, 2, and so on represent a meter read.
>
> > > > > My goal is to create a map, and then pass that around in other
> > > > > functions.
>
> > > > > Thanks.
> > > > > cmn
>
> > > > > --
> > > > > 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: Filling let local variable from sequence

2011-06-30 Thread Mark Rathwell
Not sure what you mean by 'row of vectors', and 'break up each row'.

On Thu, Jun 30, 2011 at 3:20 PM, octopusgrabbus wrote:

> If I have rows of vectors, such as the return from clojure-csv\parse-
> csv
>
> ["a" 1 "b" 2 "c" 3 "d" 4]
> ["e" 5 "f" 6 "g" 7 "h" 8]
>
> How can I break up each row?
>
> I've tried doseq in the let statement, but get an error.
>
>
> On Jun 30, 2:27 pm, octopusgrabbus  wrote:
> > Thanks. That did it.
> >
> > On Jun 30, 1:22 pm, Mark Rathwell  wrote:
> >
> >
> >
> >
> >
> >
> >
> > > One way would be:
> >
> > > (defn map-func
> > >"test map function"
> > >[]
> > >(let [mtr-seq (vector "a" 1 "b" 2 "c" 3 "d" 4)
> > >  read-map (apply hash-map mtr-seq)
> > >  (println read-map)))
> >
> > > On Thu, Jun 30, 2011 at 1:09 PM, octopusgrabbus <
> octopusgrab...@gmail.com>wrote:
> >
> > > > Given this function
> >
> > > > (defn map-func
> > > >"test map function"
> > > >[]
> > > >(let [mtr-seq (vector "a" 1 "b" 2 "c" 3 "d" 4)
> > > >  read-map ()
> > > >  (println read-map)))
> >
> > > > I want to load read-map with the keys and values from mtr-seq.
> >
> > > > Eventually, this data is going to be from the return from parse-csv
> > > > (clojure-csv), but I seem to be making more progress using simpler
> > > > examples.
> >
> > > > The "a", "b", and so on represent a character string premise id, and
> > > > the 1, 2, and so on represent a meter read.
> >
> > > > My goal is to create a map, and then pass that around in other
> > > > functions.
> >
> > > > Thanks.
> > > > cmn
> >
> > > > --
> > > > 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: Filling let local variable from sequence

2011-06-30 Thread octopusgrabbus
If I have rows of vectors, such as the return from clojure-csv\parse-
csv

["a" 1 "b" 2 "c" 3 "d" 4]
["e" 5 "f" 6 "g" 7 "h" 8]

How can I break up each row?

I've tried doseq in the let statement, but get an error.


On Jun 30, 2:27 pm, octopusgrabbus  wrote:
> Thanks. That did it.
>
> On Jun 30, 1:22 pm, Mark Rathwell  wrote:
>
>
>
>
>
>
>
> > One way would be:
>
> > (defn map-func
> >    "test map function"
> >    []
> >    (let [mtr-seq (vector "a" 1 "b" 2 "c" 3 "d" 4)
> >          read-map (apply hash-map mtr-seq)
> >          (println read-map)))
>
> > On Thu, Jun 30, 2011 at 1:09 PM, octopusgrabbus 
> > wrote:
>
> > > Given this function
>
> > > (defn map-func
> > >    "test map function"
> > >    []
> > >    (let [mtr-seq (vector "a" 1 "b" 2 "c" 3 "d" 4)
> > >          read-map ()
> > >          (println read-map)))
>
> > > I want to load read-map with the keys and values from mtr-seq.
>
> > > Eventually, this data is going to be from the return from parse-csv
> > > (clojure-csv), but I seem to be making more progress using simpler
> > > examples.
>
> > > The "a", "b", and so on represent a character string premise id, and
> > > the 1, 2, and so on represent a meter read.
>
> > > My goal is to create a map, and then pass that around in other
> > > functions.
>
> > > Thanks.
> > > cmn
>
> > > --
> > > 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: Filling let local variable from sequence

2011-06-30 Thread octopusgrabbus
Thanks. That did it.

On Jun 30, 1:22 pm, Mark Rathwell  wrote:
> One way would be:
>
> (defn map-func
>    "test map function"
>    []
>    (let [mtr-seq (vector "a" 1 "b" 2 "c" 3 "d" 4)
>          read-map (apply hash-map mtr-seq)
>          (println read-map)))
>
> On Thu, Jun 30, 2011 at 1:09 PM, octopusgrabbus 
> wrote:
>
>
>
>
>
>
>
>
>
> > Given this function
>
> > (defn map-func
> >    "test map function"
> >    []
> >    (let [mtr-seq (vector "a" 1 "b" 2 "c" 3 "d" 4)
> >          read-map ()
> >          (println read-map)))
>
> > I want to load read-map with the keys and values from mtr-seq.
>
> > Eventually, this data is going to be from the return from parse-csv
> > (clojure-csv), but I seem to be making more progress using simpler
> > examples.
>
> > The "a", "b", and so on represent a character string premise id, and
> > the 1, 2, and so on represent a meter read.
>
> > My goal is to create a map, and then pass that around in other
> > functions.
>
> > Thanks.
> > cmn
>
> > --
> > 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: Filling let local variable from sequence

2011-06-30 Thread Mark Rathwell
One way would be:

(defn map-func
   "test map function"
   []
   (let [mtr-seq (vector "a" 1 "b" 2 "c" 3 "d" 4)
 read-map (apply hash-map mtr-seq)
 (println read-map)))


On Thu, Jun 30, 2011 at 1:09 PM, octopusgrabbus wrote:

>
> Given this function
>
> (defn map-func
>"test map function"
>[]
>(let [mtr-seq (vector "a" 1 "b" 2 "c" 3 "d" 4)
>  read-map ()
>  (println read-map)))
>
> I want to load read-map with the keys and values from mtr-seq.
>
> Eventually, this data is going to be from the return from parse-csv
> (clojure-csv), but I seem to be making more progress using simpler
> examples.
>
> The "a", "b", and so on represent a character string premise id, and
> the 1, 2, and so on represent a meter read.
>
> My goal is to create a map, and then pass that around in other
> functions.
>
> Thanks.
> cmn
>
> --
> 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

Filling let local variable from sequence

2011-06-30 Thread octopusgrabbus

Given this function

(defn map-func
"test map function"
[]
(let [mtr-seq (vector "a" 1 "b" 2 "c" 3 "d" 4)
  read-map ()
  (println read-map)))

I want to load read-map with the keys and values from mtr-seq.

Eventually, this data is going to be from the return from parse-csv
(clojure-csv), but I seem to be making more progress using simpler
examples.

The "a", "b", and so on represent a character string premise id, and
the 1, 2, and so on represent a meter read.

My goal is to create a map, and then pass that around in other
functions.

Thanks.
cmn

-- 
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