Re: Implicit style streams in Clojure

2010-02-08 Thread Michał Marczyk
Use let:

(defn foo [...]
  (let [helper (fn [...] ...)]
(helper ...)))

or letfn:

(defn foo [...]
  (letfn [(helper [...] ...)]
(helper ...)))

The latter allows you to introduce mutually recursive functions.

Sincerely,
Michał

-- 
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: Implicit style streams in Clojure

2010-02-08 Thread Kevin Downey
don't use def inside functions, ever. in scheme define is lexically scoped,
so you do that sort of thing. clojure is not scheme. if you want a lexically
scoped function use a lexical scoping construct like let or letfn.

On Mon, Feb 8, 2010 at 12:12 PM, Brenton bashw...@gmail.com wrote:

 What is the Clojure best practice, if there is one, for writing a
 function like this:

 pre
 (defn integral [integrand initial-value dt]
  (def --integral (cons initial-value
  (lazy-seq (add-streams (scale-
 streams integrand dt)

 --integral
  --integral)
 /pre

 integrand is a stream of values.

 I don't like the fact that --integral is visible outside of the
 integral function but I don't know how else to implement this
 efficiently. I am using -- here as a naming convention to identify
 vars that are defined within other functions.

 Also, what is general feeling about defs inside of functions?

 Brenton

 --
 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.comclojure%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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: Implicit style streams in Clojure

2010-02-08 Thread Brenton
letfn is exactly what I was looking for.

Thank you.

On Feb 8, 12:15 pm, Michał Marczyk michal.marc...@gmail.com wrote:
 Use let:

 (defn foo [...]
   (let [helper (fn [...] ...)]
     (helper ...)))

 or letfn:

 (defn foo [...]
   (letfn [(helper [...] ...)]
     (helper ...)))

 The latter allows you to introduce mutually recursive functions.

 Sincerely,
 Michał

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