Re: defn with inline specs?

2017-06-19 Thread Alex Miller
A spec is a commitment about what the function accepts and returns. Over time, the function may grow (by requiring less in the args or by providing more in the return). By combining the function and spec, it sends the message that you can and should change both together, rather than thinking ab

Re: defn with inline specs?

2017-06-19 Thread Daniel Compton
> We think there is a lot of value in having them independent. I agree that there's value in having them independent, and I'm not suggesting that fdef is taken away, but it seems like there's also value in having the ability to make them inline? It makes the code more concise and readable, and avo

Re: defn inside defn

2014-11-15 Thread Fluid Dynamics
On Saturday, November 15, 2014 11:31:50 AM UTC-5, Udayakumar Rayala wrote: > > twice> > > Hi, > > Is it idiomatic to have defn inside defn? eastwood throws def-in-def > warning when I have the following code: > > (defn double-square [y] > (defn square [x] (* x x)) > (+ (square y)

Re: defn inside defn

2014-11-15 Thread Andy Fingerhut
Not idiomatic. All Eastwood warnings except for one have some documentation explaining what kinds of things they warn about, and sometimes why they warn about them. The def-in-def warning documentation is available here: https://github.com/jonase/eastwood#def-in-def As it says there, def's i

Re: defn inside defn

2014-11-15 Thread David Nolen
Not idiomatic. defn is always top level. David On Sat, Nov 15, 2014 at 11:31 AM, Udayakumar Rayala wrote: > twice> > > Hi, > > Is it idiomatic to have defn inside defn? eastwood throws def-in-def warning > when I have the following code: > > (defn double-square [y] > (defn square [x] (*

Re: defn allows overwriting Protocol function without notification

2010-05-22 Thread Aaron Cohen
Sorry for the duplicate messages. -- 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 fr

Re: defn within defn

2010-02-10 Thread Hozumi
Hi, Bill. oh, letfn is what I wanted ! Thank you. Sorry, I missed preview disqussion. letfn - mutually recursive local functions http://groups.google.com/group/clojure/browse_thread/thread/a7aad1d5b94db748 letfn is pretty good. --

Re: defn within defn

2010-02-10 Thread Kevin Downey
scheme's define is scoped inside a function. clojure is not scheme. clojure's def (which defn uses) is not lexical or scoped in anyway, it always operates on global names. if you want lexical scope please use one of clojure's lexical scoping constructs, let or letfn. On Wed, Feb 10, 2010 at 1:28 P

Re: defn within defn

2010-02-10 Thread .Bill Smith
Hozumi, nested defn's are definitely not recommended. I suggest using letfn for the inner function. Bill Smith Austin, TX On Feb 10, 3:28 pm, Hozumi wrote: > Hi all. > Is it not recommended to use defn within defn? > > Normal function is faster than the function which has inner function > which

Re: defn

2010-01-25 Thread Laurent PETIT
Glen, learning by example is good, but you should consider backing it with also taking a look at the main documentation pages from clojure.org ! Concerning the topic at hand, you need to "get" : * the syntax for defn : http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/defn

Re: defn

2010-01-25 Thread Mike DeLaurentis
Yes, that's basically right. I don't know if common lisp has a similar syntax for defining functions with multiple parameter lists, but you'll definitely see it a lot in Clojure code. On Mon, Jan 25, 2010 at 10:22 AM, Glen Rubin wrote: > wow! > > So if it is called with 1 argument, then the bod

Re: defn

2010-01-25 Thread Glen Rubin
wow! So if it is called with 1 argument, then the body of the function is: (factorial n 1) But if it is called with 2 arguments then the body of the function is: (if (= n 0) acc (recur (dec n) (* acc n))) Is this a standard feature of lisp? Sorry I am very noobish. thx! On J

Re: defn

2010-01-25 Thread Mike DeLaurentis
That's defining a function factorial that can be called with either one or two arguments. When called with one argument, it immediately calls itself with two arguments. So the (factorial n 1) call provides acc with an initial value of 1. The ([n] and ([n acc] lines are the declarations of the pa

Re: defn memory question

2009-06-26 Thread Rich Claxton
Thanks for all the interesting answers. On Jun 25, 5:23 pm, Stuart Sierra wrote: > On Jun 25, 6:25 am, RichClaxton wrote: > > > Hello I have just started learning Clojure and functional programming, > > quick question, what happens internally when I do a defn, does this > > create the byte code

Re: defn memory question

2009-06-25 Thread Stuart Sierra
On Jun 25, 6:25 am, Rich Claxton wrote: > Hello I have just started learning Clojure and functional programming, > quick question, what happens internally when I do a defn, does this > create the byte code, or a ref to the function which is stored, as it > does actually create a function object,

Re: defn memory question

2009-06-25 Thread Four of Seventeen
On Jun 25, 8:36 am, Emeka wrote: > From Steve's post > Symbol objects are subject to garbage collection, but the "namespace" and > "name" strings that identify them are not. Those strings are "interned" via > the "intern" method on java.lang.String. Recent JVMs do collect unused interned strings

Re: defn memory question

2009-06-25 Thread Emeka
>From Steve's post Symbol objects are subject to garbage collection, but the "namespace" and "name" strings that identify them are not. Those strings are "interned" via the "intern" method on java.lang.String. Once a String is interned, there exists a single canonical String object that represents

Re: defn memory question

2009-06-25 Thread Konrad Hinsen
On Jun 25, 2009, at 12:25, Rich Claxton wrote: > Hello I have just started learning Clojure and functional programming, > quick question, what happens internally when I do a defn, does this > create the byte code, or a ref to the function which is stored, as it > does actually create a function o