Re: Anonymous Macros

2012-11-06 Thread Alex Baranosky
Yep. `macro-let` is what you're looking for.

On Tue, Nov 6, 2012 at 10:41 PM, Baishampayan Ghose wrote:

> Take a look at tools.macro/macrolet.
>
> https://github.com/clojure/tools.macro/
>
> Regards,
> BG
>
> Sent from phone. Please excuse brevity.
> On 6 Nov 2012 19:10, "Sean Neilan"  wrote:
>
>> I was hoping to write a macro inside of a let statement. The macro would
>> be returned from the let and keep closures to whatever was defined in the
>> let.
>> Also, if possible, define multiple global macros inside of a let
>> statement so it's as if the let is returning multiple values.
>>
>>
>>
>> On Tue, Nov 6, 2012 at 9:07 PM, jaime  wrote:
>>
>>> May I know in what circumstances would an anonymous macro be applied? -
>>> I just don't think there's a way to define anonymous macro but maybe we can
>>> make a workaround by manipulating the macro syntax...
>>>
>>> 在 2012年11月7日星期三UTC+8上午8时17分37秒,Sean Neilan写道:
>>>
 Is there any way to write an anonymous macro in Clojure?

 This post:
 http://stackoverflow.com/**questions/4074961/anonymous-**
 macros-in-clojure
 says it's possible with some hacks and in version 1.3 Clojure will have
 some kind of support for this.

 Thank you for your time.

 -Sean

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

-- 
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: Anonymous Macros

2012-11-06 Thread Baishampayan Ghose
Take a look at tools.macro/macrolet.

https://github.com/clojure/tools.macro/

Regards,
BG

Sent from phone. Please excuse brevity.
On 6 Nov 2012 19:10, "Sean Neilan"  wrote:

> I was hoping to write a macro inside of a let statement. The macro would
> be returned from the let and keep closures to whatever was defined in the
> let.
> Also, if possible, define multiple global macros inside of a let statement
> so it's as if the let is returning multiple values.
>
>
>
> On Tue, Nov 6, 2012 at 9:07 PM, jaime  wrote:
>
>> May I know in what circumstances would an anonymous macro be applied? - I
>> just don't think there's a way to define anonymous macro but maybe we can
>> make a workaround by manipulating the macro syntax...
>>
>> 在 2012年11月7日星期三UTC+8上午8时17分37秒,Sean Neilan写道:
>>
>>> Is there any way to write an anonymous macro in Clojure?
>>>
>>> This post:
>>> http://stackoverflow.com/**questions/4074961/anonymous-**
>>> macros-in-clojure
>>> says it's possible with some hacks and in version 1.3 Clojure will have
>>> some kind of support for this.
>>>
>>> Thank you for your time.
>>>
>>> -Sean
>>>
>>>  --
>> 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: Anonymous Macros

2012-11-06 Thread jaime
Well, logically the difference between a function and macro is just that 
the parameters will be evaluated in a function call but will not in a macro 
call. I suppose you can use anonymous function to achieve what you may want 
in a LET statement. 

And as SunNing said, Clojure will use meta tag ":macro true" of *Var* to 
identify a macro, but those var-look things defined within LET bindings are 
not *Vars*(they called locals?), I guess we are not able to make any 
'anonymous macros' there.

Maybe you can give us a more specific scenario of your requirement so that 
we can figure out how to make it work without 'anonymous macros'.

在 2012年11月7日星期三UTC+8上午11时12分24秒,Sean Neilan写道:
>
> I was hoping to write a macro inside of a let statement. The macro would 
> be returned from the let and keep closures to whatever was defined in the 
> let.
> Also, if possible, define multiple global macros inside of a let statement 
> so it's as if the let is returning multiple values.
>
>
> On Tue, Nov 6, 2012 at 9:07 PM, jaime >wrote:
>
>> May I know in what circumstances would an anonymous macro be applied? - I 
>> just don't think there's a way to define anonymous macro but maybe we can 
>> make a workaround by manipulating the macro syntax...
>>
>> 在 2012年11月7日星期三UTC+8上午8时17分37秒,Sean Neilan写道:
>>
>>> Is there any way to write an anonymous macro in Clojure?
>>>
>>> This post:
>>> http://stackoverflow.com/**questions/4074961/anonymous-**
>>> macros-in-clojure
>>> says it's possible with some hacks and in version 1.3 Clojure will have 
>>> some kind of support for this.
>>>
>>> Thank you for your time.
>>>
>>> -Sean
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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: Anonymous Macros

2012-11-06 Thread Sean Neilan
I was hoping to write a macro inside of a let statement. The macro would be
returned from the let and keep closures to whatever was defined in the let.
Also, if possible, define multiple global macros inside of a let statement
so it's as if the let is returning multiple values.


On Tue, Nov 6, 2012 at 9:07 PM, jaime  wrote:

> May I know in what circumstances would an anonymous macro be applied? - I
> just don't think there's a way to define anonymous macro but maybe we can
> make a workaround by manipulating the macro syntax...
>
> 在 2012年11月7日星期三UTC+8上午8时17分37秒,Sean Neilan写道:
>
>> Is there any way to write an anonymous macro in Clojure?
>>
>> This post:
>> http://stackoverflow.com/**questions/4074961/anonymous-**
>> macros-in-clojure
>> says it's possible with some hacks and in version 1.3 Clojure will have
>> some kind of support for this.
>>
>> Thank you for your time.
>>
>> -Sean
>>
>>  --
> 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: Anonymous Macros

2012-11-06 Thread Sean Neilan
I was hoping to write a macro inside of a let statement. The macro would be
returned from the let and keep closures to whatever was defined in the let.
Also, if possible, define multiple global macros inside of a let statement
so it's as if the let is returning multiple values.



On Tue, Nov 6, 2012 at 9:07 PM, jaime  wrote:

> May I know in what circumstances would an anonymous macro be applied? - I
> just don't think there's a way to define anonymous macro but maybe we can
> make a workaround by manipulating the macro syntax...
>
> 在 2012年11月7日星期三UTC+8上午8时17分37秒,Sean Neilan写道:
>
>> Is there any way to write an anonymous macro in Clojure?
>>
>> This post:
>> http://stackoverflow.com/**questions/4074961/anonymous-**
>> macros-in-clojure
>> says it's possible with some hacks and in version 1.3 Clojure will have
>> some kind of support for this.
>>
>> Thank you for your time.
>>
>> -Sean
>>
>>  --
> 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: Anonymous Macros

2012-11-06 Thread jaime
May I know in what circumstances would an anonymous macro be applied? - I 
just don't think there's a way to define anonymous macro but maybe we can 
make a workaround by manipulating the macro syntax...

在 2012年11月7日星期三UTC+8上午8时17分37秒,Sean Neilan写道:
>
> Is there any way to write an anonymous macro in Clojure?
>
> This post:
> http://stackoverflow.com/questions/4074961/anonymous-macros-in-clojure
> says it's possible with some hacks and in version 1.3 Clojure will have 
> some kind of support for this.
>
> Thank you for your time.
>
> -Sean
>
>

-- 
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: Anonymous Macros

2012-11-06 Thread Sun Ning
I'm afraid not. Macro should be bound on a var. The clojure compile 
checks an attribute (isMacro) on a var to determine if it's a macro or 
function.

And Since a macro has no value, you cannot write it with some literals.

On Wed 07 Nov 2012 08:16:42 AM CST, Sean Neilan wrote:

Is there any way to write an anonymous macro in Clojure?

This post:
http://stackoverflow.com/questions/4074961/anonymous-macros-in-clojure
says it's possible with some hacks and in version 1.3 Clojure will
have some kind of support for this.

Thank you for your time.

-Sean

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


Anonymous Macros

2012-11-06 Thread Sean Neilan
Is there any way to write an anonymous macro in Clojure?

This post:
http://stackoverflow.com/questions/4074961/anonymous-macros-in-clojure
says it's possible with some hacks and in version 1.3 Clojure will have
some kind of support for this.

Thank you for your time.

-Sean

-- 
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: Combining Complement and Not

2012-11-06 Thread James MacAulay
I'd say the simplest answer is just that functions *are* values, they are 
never logical-false, and (not) is based on logical falseness. Giving (not) 
a special case for functions would make it less composable by trying to 
make it do more.

-James


On Tuesday, 6 November 2012 14:55:53 UTC-5, Charles Comstock wrote:
>
> I understand that, hence the example being to check if the value was a 
> function, since returning false from not'ing a function didn't make sense 
> to me. The change I was inquiring about applied to your example would be;
>
> (filter (fnot even?) [1 2 3 4 5 6 7]) => (1 3 5 7)
> (filter fnot [true false true]) => [false true false]
>
> So I fully understand that one is operating on values, and one is 
> operating on functions. What I was asking, is if it's ever useful to 
> execute not on a function but treat it as a value, just as it doesn't make 
> sense to execute complement on values instead of functions. Given that it 
> seemed the vast majority of use cases are distinct dependent on if you are 
> dealing with functions or values, I was questioning if the functions could 
> be combined to do the right thing depending on if it was a value or a 
> function. I was asking for arguments for and against that, but concluded it 
> was probably was due to complecting and was asking for verification.
>
> Thanks,
>
> Charlie
>
> On Tuesday, November 6, 2012 4:03:44 AM UTC-6, Stathis Sideris wrote:
>>
>> The difference between not and complement is that not takes a *value* and 
>> produces a new *value* which is true if the original was false (and vice 
>> versa) while complement takes a *function* and produces a new *function 
>> *which 
>> returns true in the cases where the original function would return false.
>>
>> Here is an example that shows how complement can result in more concise 
>> code in comparison to not:
>>
>> user> (filter (fn [x] (not (even? x))) [1 2 3 4 5 6 7])
>> (1 3 5 7)
>> user> (filter (complement even?) [1 2 3 4 5 6 7])
>> (1 3 5 7)
>>
>> (of course you could just use odd? in this case, but it's only an 
>> example).
>>
>> I hope that clears it up.
>>
>> Stathis
>>
>> On Monday, 5 November 2012 23:12:03 UTC, Charles Comstock wrote:
>>>
>>> Hi All,
>>>
>>> I quite like Clojure but have been confused from time to time on 
>>> particular design choices. I find understanding the root cause of these 
>>> decisions helps to understand the language better. As example, the fact 
>>> that complement and not are separate functions has been puzzling me for a 
>>> bit [1]. The implementation of not and complement is roughly;
>>>
>>> (defn not [x] (if x false true))
>>> (defn complement [f] 
>>>   (fn 
>>>  ([] (not (f)))
>>>  ([x] (not (f x)))
>>>  ([x y] (not (f x y)))
>>>  ([x y & zs] (not (apply f x y zs)
>>>
>>> What I'm wondering is if it's purely for performance, historical or 
>>> idiomatic reasons that it's not;
>>>
>>>
>>> (defn fnot [arg]
>>>   (if (ifn? arg)
>>> (fn
>>>   ([] (fnot (arg)))
>>>   ([x] (fnot (arg x)))
>>>   ([x y] (fnot (arg x y)))
>>>   ([x y & zs] (fnot (apply arg x y zs
>>> (if arg false true)))
>>>
>>> Perhaps a multi-method could also be appropriate here, though I'm not 
>>> exactly certain what the appropriate dispatch function would be. I follow 
>>> why bit-not is a separate function as the intended meaning is clearly 
>>> different, but the implied meaning of not seems to be the same as 
>>> complement which is why it seems odd that they are different methods. 
>>>
>>> After doing some experimentation with these, I finally realized that (not 
>>> identity) yields false, but I'm not quite following that use case. I'm 
>>> guessing the idiomatic argument against fnot is that it would complect not 
>>> and complement unnecessarily?
>>>
>>> While pouring through the clojure.core source, I also saw a few functions 
>>> like not-every? which use (comp not every?) instead of (complement every?). 
>>> This led me to question why complement is not implemented as;
>>>
>>>
>>> (defn complement [f] (comp not f))
>>>
>>>
>>> Is there a difference that I'm just not seeing? Or is that just a side 
>>> effect of either performance or dependency ordering in clojure.core [2].
>>>
>>> I think I may have answered my own question concerning fnot in a roundabout 
>>> manner, but I found the process of discovering this illuminating. Can 
>>> anyone else shed light on this, or am I correct in concluding that fnot 
>>> would complect not and complement?
>>>
>>> Thanks,
>>>  Charlie
>>>
>>> 1. I frequently misread comp as complement and not compose in point free 
>>> code, so perhaps that confusion is why complement is oddly jarring to me.
>>>
>>> 2. not-every? and not-any? are implemented using def instead of defn and 
>>> manually set meta :arglist, despite defn already being defined, is this 
>>> just for historical reasons?
>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google
Groups "Cloju

Re: How to call javascript's call/apply to set context/scope with "this" from clojurescript?

2012-11-06 Thread Frank Siebenlist
Too easy ;-)

Thanks, FrankS.



On Nov 6, 2012, at 2:38 PM, David Nolen  wrote:

> You could do: (.call f context ...)
> 
> 
> 
> 
> On Tue, Nov 6, 2012 at 5:33 PM, Frank Siebenlist  
> wrote:
> In Javascript you seem to be able to set the context for "this" to any 
> fn-object by specifying your desired context's "this" in the call/apply call.
> 
> (never knew about this option - feels like an aweful hack to define 
> invocation-scope but some libraries use it… see 
> http://www.slideshare.net/moduscreate/javascript-classes-and-scoping for a 
> good explanation).
> 
> The CLJS compiler seems to fill-in the "this" with a nil for f.call(null,…) 
> invocations.
> 
> Q is how do you specify this context-this in CLJS as the context/scope for 
> the invocation?
> 
> -FrankS.
> 
> --
> 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: How to call javascript's call/apply to set context/scope with "this" from clojurescript?

2012-11-06 Thread David Nolen
You could do: (.call f context ...)




On Tue, Nov 6, 2012 at 5:33 PM, Frank Siebenlist  wrote:

> In Javascript you seem to be able to set the context for "this" to any
> fn-object by specifying your desired context's "this" in the call/apply
> call.
>
> (never knew about this option - feels like an aweful hack to define
> invocation-scope but some libraries use it… see
> http://www.slideshare.net/moduscreate/javascript-classes-and-scoping for
> a good explanation).
>
> The CLJS compiler seems to fill-in the "this" with a nil for
> f.call(null,…) invocations.
>
> Q is how do you specify this context-this in CLJS as the context/scope for
> the invocation?
>
> -FrankS.
>
> --
> 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

How to call javascript's call/apply to set context/scope with "this" from clojurescript?

2012-11-06 Thread Frank Siebenlist
In Javascript you seem to be able to set the context for "this" to any 
fn-object by specifying your desired context's "this" in the call/apply call.

(never knew about this option - feels like an aweful hack to define 
invocation-scope but some libraries use it… see 
http://www.slideshare.net/moduscreate/javascript-classes-and-scoping for a good 
explanation).

The CLJS compiler seems to fill-in the "this" with a nil for f.call(null,…) 
invocations.

Q is how do you specify this context-this in CLJS as the context/scope for the 
invocation?

-FrankS.

-- 
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: Cdr car

2012-11-06 Thread Michael Gardner
On Nov 6, 2012, at 11:48 , Sean Corfield  wrote:

> On Tue, Nov 6, 2012 at 9:34 AM, JvJ  wrote:
>> There's quite a number of functions like caar, cadr, cadadr, etc.  It's
>> lengthy to do that in clojure with just first and rest.
> 
> Clojure does have ffirst, fnext, nfirst, nnext tho' - and I'd question
> why you'd need to string several of them together... almost sounds
> like you'd want different data structures or a more descriptive way to
> access data in them? Perhaps vectors and maps and get-in?

Don't forget destructuring! I love that Clojure's pervasive destructuring 
support single-handedly eliminates many of these problems.

-- 
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: Combining Complement and Not

2012-11-06 Thread Charles Comstock
I understand that, hence the example being to check if the value was a 
function, since returning false from not'ing a function didn't make sense 
to me. The change I was inquiring about applied to your example would be;

(filter (fnot even?) [1 2 3 4 5 6 7]) => (1 3 5 7)
(filter fnot [true false true]) => [false true false]

So I fully understand that one is operating on values, and one is operating 
on functions. What I was asking, is if it's ever useful to execute not on a 
function but treat it as a value, just as it doesn't make sense to execute 
complement on values instead of functions. Given that it seemed the vast 
majority of use cases are distinct dependent on if you are dealing with 
functions or values, I was questioning if the functions could be combined 
to do the right thing depending on if it was a value or a function. I was 
asking for arguments for and against that, but concluded it was probably 
was due to complecting and was asking for verification.

Thanks,

Charlie

On Tuesday, November 6, 2012 4:03:44 AM UTC-6, Stathis Sideris wrote:
>
> The difference between not and complement is that not takes a *value* and 
> produces a new *value* which is true if the original was false (and vice 
> versa) while complement takes a *function* and produces a new *function 
> *which 
> returns true in the cases where the original function would return false.
>
> Here is an example that shows how complement can result in more concise 
> code in comparison to not:
>
> user> (filter (fn [x] (not (even? x))) [1 2 3 4 5 6 7])
> (1 3 5 7)
> user> (filter (complement even?) [1 2 3 4 5 6 7])
> (1 3 5 7)
>
> (of course you could just use odd? in this case, but it's only an example).
>
> I hope that clears it up.
>
> Stathis
>
> On Monday, 5 November 2012 23:12:03 UTC, Charles Comstock wrote:
>>
>> Hi All,
>>
>> I quite like Clojure but have been confused from time to time on 
>> particular design choices. I find understanding the root cause of these 
>> decisions helps to understand the language better. As example, the fact 
>> that complement and not are separate functions has been puzzling me for a 
>> bit [1]. The implementation of not and complement is roughly;
>>
>> (defn not [x] (if x false true))
>> (defn complement [f] 
>>   (fn 
>>  ([] (not (f)))
>>  ([x] (not (f x)))
>>  ([x y] (not (f x y)))
>>  ([x y & zs] (not (apply f x y zs)
>>
>> What I'm wondering is if it's purely for performance, historical or 
>> idiomatic reasons that it's not;
>>
>>
>> (defn fnot [arg]
>>   (if (ifn? arg)
>> (fn
>>   ([] (fnot (arg)))
>>   ([x] (fnot (arg x)))
>>   ([x y] (fnot (arg x y)))
>>   ([x y & zs] (fnot (apply arg x y zs
>> (if arg false true)))
>>
>> Perhaps a multi-method could also be appropriate here, though I'm not 
>> exactly certain what the appropriate dispatch function would be. I follow 
>> why bit-not is a separate function as the intended meaning is clearly 
>> different, but the implied meaning of not seems to be the same as complement 
>> which is why it seems odd that they are different methods. 
>>
>> After doing some experimentation with these, I finally realized that (not 
>> identity) yields false, but I'm not quite following that use case. I'm 
>> guessing the idiomatic argument against fnot is that it would complect not 
>> and complement unnecessarily?
>>
>> While pouring through the clojure.core source, I also saw a few functions 
>> like not-every? which use (comp not every?) instead of (complement every?). 
>> This led me to question why complement is not implemented as;
>>
>>
>> (defn complement [f] (comp not f))
>>
>>
>> Is there a difference that I'm just not seeing? Or is that just a side 
>> effect of either performance or dependency ordering in clojure.core [2].
>>
>> I think I may have answered my own question concerning fnot in a roundabout 
>> manner, but I found the process of discovering this illuminating. Can anyone 
>> else shed light on this, or am I correct in concluding that fnot would 
>> complect not and complement?
>>
>> Thanks,
>>  Charlie
>>
>> 1. I frequently misread comp as complement and not compose in point free 
>> code, so perhaps that confusion is why complement is oddly jarring to me.
>>
>> 2. not-every? and not-any? are implemented using def instead of defn and 
>> manually set meta :arglist, despite defn already being defined, is this just 
>> for historical reasons?
>>
>>
>>

-- 
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: Adding a comma to end of clojure sequence

2012-11-06 Thread octopusgrabbus
This is solved. I am adding a blank field, which gets me my trailing comma.

On Tuesday, November 6, 2012 2:40:19 PM UTC-5, octopusgrabbus wrote:
>
> Is it possible to add an unquoted comma at the end of a Clojure sequence, 
> while using clojure.data.csv's write-csv?
>
> (defn write-csv-file
>   "Writes a csv file using a key and an s-o-s"
>   [out-sos out-file]
>
>   (if (= dbg 1)
> (println (first out-sos), "\n", out-file))
>
>   (spit out-file "" :append false)
>   (with-open [out-data (io/writer out-file)]
>   (csv/write-csv out-data out-sos)))
>
> This code writes my sequence of sequences out just fine. All I want to do is 
> add a trailing comma.
>
>
>

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

Adding a comma to end of clojure sequence

2012-11-06 Thread octopusgrabbus
Is it possible to add an unquoted comma at the end of a Clojure sequence, 
while using clojure.data.csv's write-csv?

(defn write-csv-file
  "Writes a csv file using a key and an s-o-s"
  [out-sos out-file]

  (if (= dbg 1)
(println (first out-sos), "\n", out-file))

  (spit out-file "" :append false)
  (with-open [out-data (io/writer out-file)]
  (csv/write-csv out-data out-sos)))

This code writes my sequence of sequences out just fine. All I want to do is 
add a trailing comma.


-- 
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: Cdr car

2012-11-06 Thread Sean Corfield
On Tue, Nov 6, 2012 at 9:34 AM, JvJ  wrote:
> There's quite a number of functions like caar, cadr, cadadr, etc.  It's
> lengthy to do that in clojure with just first and rest.

Clojure does have ffirst, fnext, nfirst, nnext tho' - and I'd question
why you'd need to string several of them together... almost sounds
like you'd want different data structures or a more descriptive way to
access data in them? Perhaps vectors and maps and get-in?
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: Cdr car

2012-11-06 Thread JvJ
After seeing this thread I looked into car and cdr, and there's one thing I 
really liked about them: the various compositions.

There's quite a number of functions like caar, cadr, cadadr, etc.  It's 
lengthy to do that in clojure with just first and rest.

On Tuesday, 16 October 2012 18:40:24 UTC-4, Curtis wrote:
>
> Hello - I was familar with lisp years ago and am very new to clojure.
>
> I am having a hard time understanding how to find 'car' and 'cdr'.
>
> The nice thing about these functions is they always seem to be a part of 
> lisp.
>
> I would like to use the little lisper to teach lisp to my co-workers so 
> that we can adopt Clojure.
>
> How can i import cdr or car? 
>
> I know i can write these manually  or alias them to 'first' and 'rest' - 
> are they a part of the language?
>
> Cons appears to be around.
>
>
>
>

-- 
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: Free Clojure Course

2012-11-06 Thread JvJ
Seems like nifty shenanigans but how much does this course cover?
It would be nice to see a course that covered some of the more advanced 
features of the language,
like multimethods, concurrent programming, interop, etc.

On Sunday, 28 October 2012 06:54:02 UTC-4, Ryan Kelker wrote:
>
> There's a free 19 part series on basic Clojure @ 
> http://www.udemy.com/clojure-code
>

-- 
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: Free Clojure Course

2012-11-06 Thread JvJ
Seems like nifty shenanigans but how much does this course cover?

On Sunday, 28 October 2012 06:54:02 UTC-4, Ryan Kelker wrote:
>
> There's a free 19 part series on basic Clojure @ 
> http://www.udemy.com/clojure-code
>

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

2012-11-06 Thread Bronsa
What about using destructuring?
(defn F [[a b c d]] (+ a b c d))

2012/11/6 the80srobot 

> If I understand this right, you're looking for something like Lua's unpack
> function. AFAIK you will not be able to do this in Clojure using functions,
> because Clojure functions can only return one argument. The only way to
> achieve this behavior would by by transforming your calls using reader
> macros and then eval. I do not recommend doing this.
>
> I understand that something like unpack is a more general case of apply,
> but I can't think of any scenario where apply isn't enough - out of
> interest, what are you trying to do?
>
> -Adam
>
>
> On Monday, November 5, 2012 5:45:46 AM UTC+1, cej38 wrote:
>>
>> Say you are given a vector A=[a1 a2 a3 a4] by some function/library/Java
>> call/whatever.
>> You want to use A in some function F that expects the values a1 a2 a3 a4
>> but not in the form of A; for example (defn F [w x y z] (+ w x y z)).
>> Is there some function G that you can use on A such that (F (G A)) would
>> give the correct answer?
>> I now know ways of getting around this, for example in the overly simple
>> problem I gave above I would use (eval (cons F [1 2 3 4])).
>> But I have came across problems where I have had to spend a large amount
>> of time trying to figure out how to do this correctly.
>> I would think that there could be something to act as G.
>> Is there something like this?  It would definitely simplify things from
>> time to time.
>>
>  --
> 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: unseq

2012-11-06 Thread the80srobot
If I understand this right, you're looking for something like Lua's unpack 
function. AFAIK you will not be able to do this in Clojure using functions, 
because Clojure functions can only return one argument. The only way to 
achieve this behavior would by by transforming your calls using reader 
macros and then eval. I do not recommend doing this.

I understand that something like unpack is a more general case of apply, 
but I can't think of any scenario where apply isn't enough - out of 
interest, what are you trying to do?

-Adam

On Monday, November 5, 2012 5:45:46 AM UTC+1, cej38 wrote:
>
> Say you are given a vector A=[a1 a2 a3 a4] by some function/library/Java 
> call/whatever.
> You want to use A in some function F that expects the values a1 a2 a3 a4 
> but not in the form of A; for example (defn F [w x y z] (+ w x y z)).  
> Is there some function G that you can use on A such that (F (G A)) would 
> give the correct answer? 
> I now know ways of getting around this, for example in the overly simple 
> problem I gave above I would use (eval (cons F [1 2 3 4])).  
> But I have came across problems where I have had to spend a large amount 
> of time trying to figure out how to do this correctly.  
> I would think that there could be something to act as G.  
> Is there something like this?  It would definitely simplify things from 
> time to time.
>

-- 
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: Combining Complement and Not

2012-11-06 Thread Stathis Sideris
The difference between not and complement is that not takes a *value* and 
produces a new *value* which is true if the original was false (and vice 
versa) while complement takes a *function* and produces a new *function *which 
returns true in the cases where the original function would return false.

Here is an example that shows how complement can result in more concise 
code in comparison to not:

user> (filter (fn [x] (not (even? x))) [1 2 3 4 5 6 7])
(1 3 5 7)
user> (filter (complement even?) [1 2 3 4 5 6 7])
(1 3 5 7)

(of course you could just use odd? in this case, but it's only an example).

I hope that clears it up.

Stathis

On Monday, 5 November 2012 23:12:03 UTC, Charles Comstock wrote:
>
> Hi All,
>
> I quite like Clojure but have been confused from time to time on 
> particular design choices. I find understanding the root cause of these 
> decisions helps to understand the language better. As example, the fact 
> that complement and not are separate functions has been puzzling me for a 
> bit [1]. The implementation of not and complement is roughly;
>
> (defn not [x] (if x false true))
> (defn complement [f] 
>   (fn 
>  ([] (not (f)))
>  ([x] (not (f x)))
>  ([x y] (not (f x y)))
>  ([x y & zs] (not (apply f x y zs)
>
> What I'm wondering is if it's purely for performance, historical or idiomatic 
> reasons that it's not;
>
>
> (defn fnot [arg]
>   (if (ifn? arg)
> (fn
>   ([] (fnot (arg)))
>   ([x] (fnot (arg x)))
>   ([x y] (fnot (arg x y)))
>   ([x y & zs] (fnot (apply arg x y zs
> (if arg false true)))
>
> Perhaps a multi-method could also be appropriate here, though I'm not exactly 
> certain what the appropriate dispatch function would be. I follow why bit-not 
> is a separate function as the intended meaning is clearly different, but the 
> implied meaning of not seems to be the same as complement which is why it 
> seems odd that they are different methods. 
>
> After doing some experimentation with these, I finally realized that (not 
> identity) yields false, but I'm not quite following that use case. I'm 
> guessing the idiomatic argument against fnot is that it would complect not 
> and complement unnecessarily?
>
> While pouring through the clojure.core source, I also saw a few functions 
> like not-every? which use (comp not every?) instead of (complement every?). 
> This led me to question why complement is not implemented as;
>
>
> (defn complement [f] (comp not f))
>
>
> Is there a difference that I'm just not seeing? Or is that just a side effect 
> of either performance or dependency ordering in clojure.core [2].
>
> I think I may have answered my own question concerning fnot in a roundabout 
> manner, but I found the process of discovering this illuminating. Can anyone 
> else shed light on this, or am I correct in concluding that fnot would 
> complect not and complement?
>
> Thanks,
>  Charlie
>
> 1. I frequently misread comp as complement and not compose in point free 
> code, so perhaps that confusion is why complement is oddly jarring to me.
>
> 2. not-every? and not-any? are implemented using def instead of defn and 
> manually set meta :arglist, despite defn already being defined, is this just 
> for historical reasons?
>
>
>

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