librelist archives

« back to archive

Tail position

Tail position

From:
Ali Baitam
Date:
2013-05-09 @ 04:27
On page 31 (1st ed) there is an example absolute-value function to explain
tail position. It says the whole "if" is in tail position because whatever
it returns the whole function will return. However, the "else" clause (- x)
is in a tail position also. Does that mean a function have more than one
tail position?

Thanks

Re: [foray] Tail position

From:
Charlie Griefer
Date:
2013-05-09 @ 04:36
On May 8, 2013, at 9:27 PM, Ali Baitam <abaitam@gmail.com> wrote:

> On page 31 (1st ed) there is an example absolute-value function to 
explain tail position. It says the whole "if" is in tail position because 
whatever it returns the whole function will return. However, the "else" 
clause (- x) is in a tail position also. Does that mean a function have 
more than one tail position?

I'm a n00b (obligatory intro email soon), so this is my best guess. Yup. 
As the book states, as long as the expression results in a return out of 
the function, it's considered to be in a tail position. 

But to be clear, the "else" clause (- x) is _NOT_ in tail position because
the x is passed to the "-" function, and is not directly returned.

So the entire "if" expression is in tail position, because it's going to 
return something.
The "then" is in tail position, because it's going to return "x".

The "else" is not in tail position, because it passes x to the subtraction
function.


--
Charlie Griefer
http://charlie.griefer.com

"Give light, and the darkness will disappear of itself." 
-- Desiderius Erasmus

Re: [foray] Tail position

From:
Ali Baitam
Date:
2013-05-09 @ 04:44
Thanks Charlie. I understand that a tail position is a point where the
function returns. But is it the point where it "will" return (the whole if)
which means a function can have one tail position and one recur can be
used. Or is it "might" return which is either the "then" clause or the
whole (- x) in the "else" clause? thus a function have more than one tail
position and recur can appear in many places? I wish the author used a
better function (with recur) to beter explain tail position.

Thanks
Ali



On Thu, May 9, 2013 at 12:36 AM, Charlie Griefer <charlie@griefer.com>wrote:

> On May 8, 2013, at 9:27 PM, Ali Baitam <abaitam@gmail.com> wrote:
>
> On page 31 (1st ed) there is an example absolute-value function to explain
> tail position. It says the whole "if" is in tail position because whatever
> it returns the whole function will return. However, the "else" clause (- x)
> is in a tail position also. Does that mean a function have more than one
> tail position?
>
>
> I'm a n00b (obligatory intro email soon), so this is my best guess. Yup.
> As the book states, as long as the expression results in a return out of
> the function, it's considered to be in a tail position.
>
> But to be clear, the "else" clause (- x) is _NOT_ in tail position because
> the x is passed to the "-" function, and is not directly returned.
>
> So the entire "if" expression is in tail position, because it's going to
> return something.
> The "then" is in tail position, because it's going to return "x".
>
> The "else" is not in tail position, because it passes x to the subtraction
> function.
>
>
> --
> Charlie Griefer
> <http://charlie.griefer.com>http://charlie.griefer.com
>
> "Give light, and the darkness will disappear of itself."
> -- Desiderius Erasmus
>
>

Re: [foray] Tail position

From:
Charlie Griefer
Date:
2013-05-09 @ 04:56
On May 8, 2013, at 9:44 PM, Ali Baitam <abaitam@gmail.com> wrote:

> Thanks Charlie. I understand that a tail position is a point where the 
function returns. But is it the point where it "will" return (the whole 
if) which means a function can have one tail position and one recur can be
used. Or is it "might" return which is either the "then" clause or the 
whole (- x) in the "else" clause? thus a function have more than one tail 
position and recur can appear in many places? I wish the author used a 
better function (with recur) to beter explain tail position.

Yeah, that might not be the best example for recur, but I imagine we'll 
get into it more deeply in chapter 7. For right now, the authors are just 
trying to provide a gentle introduction to a lot of concepts.

I think that while the entire (if… ) can be considered to be in tail 
position, you're right… in this particular example there'd be no reason to
recur from it. Not that I can tell, anyway. And given that they were 
demonstrating tail position specifically for the purpose of defining it as
the one restriction towards recur, you'd think they'd have actually shown 
a function with recur :)

So my take-away at this point is… you _can_ have more than one tail 
position, and I'd wager that you _can_ recur from any of them. But of 
course you don't necessarily have to.

--
Charlie Griefer
http://charlie.griefer.com

"Give light, and the darkness will disappear of itself." 
-- Desiderius Erasmus

Re: [foray] Tail position

From:
Sean Corfield
Date:
2013-05-09 @ 05:29
Since Clojure rejects recur in a position that isn't the tail, you can
conduct a quick experiment:

(defn f [x] (if x (recur x) (recur x)))

Clojure accepts this so both the 'then' and the 'else' expressions are
considered tail position - because the whole 'if' is tail position (and
'if' is a special form, not a function call)..

Clojure doesn't accept this - as Charlie indicated:

(defn f [x] (if x (recur x) (- (recur x))))

The else expression would be tail position but a subexpression of a
function call is not.

Sean


On Wed, May 8, 2013 at 9:56 PM, Charlie Griefer <charlie@griefer.com> wrote:

> On May 8, 2013, at 9:44 PM, Ali Baitam <abaitam@gmail.com> wrote:
>
> Thanks Charlie. I understand that a tail position is a point where the
> function returns. But is it the point where it "will" return (the whole if)
> which means a function can have one tail position and one recur can be
> used. Or is it "might" return which is either the "then" clause or the
> whole (- x) in the "else" clause? thus a function have more than one tail
> position and recur can appear in many places? I wish the author used a
> better function (with recur) to beter explain tail position.
>
>
> Yeah, that might not be the best example for recur, but I imagine w e'll
> get into it more deeply in chapter 7. For right now, the authors are just
> trying to provide a gentle introduction to a lot of concepts.
>
> I think that while the entire (if… ) can be considered to be in tail
> position, you're right… in this particular example there'd be no reason to
> recur from it. Not that I can tell, anyway. And given that they were
> demonstrating tail position specifically for the purpose of defining it as
> the one restriction towards recur, you'd think they'd have actually shown a
> function with recur :)
>
> So my take-away at this point is… you _can_ have more than one tail
> position, and I'd wager that you _can_ recur from any of them. But of
> course you don't necessarily have to.
>
> --
> Charlie Griefer
> <http://charlie.griefer.com>http://charlie.griefer.com
>
> "Give light, and the darkness will disappear of itself."
> -- Desiderius Erasmus
>
>

Re: [foray] Tail position

From:
Sean Williamson
Date:
2013-05-09 @ 05:36
Nice explanation Sean!

Sidenote, would anyone be opposed to writing at least code examples in a 
markdown syntax?

eg:

```clojure
(defn f [x] (if x (recur x) (recur x)))
```

This would be so we can style the mailing list archives going forward; I 
think it may be worth thinking about as we all get into more complicated 
code examples.

On 5/8/13 10:29 PM, Sean Corfield wrote:
> Since Clojure rejects recur in a position that isn't the tail, you can 
> conduct a quick experiment:
> (defn f [x] (if x (recur x) (recur x)))
> Clojure accepts this so both the 'then' and the 'else' expressions are 
> considered tail position - because the whole 'if' is tail position 
> (and 'if' is a special form, not a function call)..
> Clojure doesn't accept this - as Charlie indicated:
> (defn f [x] (if x (recur x) (- (recur x))))
> The else expression would be tail position but a subexpression of a 
> function call is not.
> Sean
>
>
> On Wed, May 8, 2013 at 9:56 PM, Charlie Griefer <charlie@griefer.com 
> <mailto:charlie@griefer.com>> wrote:
>
>     On May 8, 2013, at 9:44 PM, Ali Baitam <abaitam@gmail.com
>     <mailto:abaitam@gmail.com>> wrote:
>
>>     Thanks Charlie. I understand that a tail position is a point
>>     where the function returns. But is it the point where it "will"
>>     return (the whole if) which means a function can have one tail
>>     position and one recur can be used. Or is it "might" return which
>>     is either the "then" clause or the whole (- x) in the "else"
>>     clause? thus a function have more than one tail position and
>>     recur can appear in many places? I wish the author used a better
>>     function (with recur) to beter explain tail position.
>
>     Yeah, that might not be the best example for recur, but I imagine
>     w e'll get into it more deeply in chapter 7. For right now, the
>     authors are just trying to provide a gentle introduction to a lot
>     of concepts.
>
>     I think that while the entire (if… ) can be considered to be in
>     tail position, you're right… in this particular example there'd be
>     no reason to recur from it. Not that I can tell, anyway. And given
>     that they were demonstrating tail position specifically for the
>     purpose of defining it as the one restriction towards recur, you'd
>     think they'd have actually shown a function with recur :)
>
>     So my take-away at this point is… you _can_ have more than one
>     tail position, and I'd wager that you _can_ recur from any of
>     them. But of course you don't necessarily have to.
>
>     --
>     Charlie Griefer
>     http://charlie.griefer.com <http://charlie.griefer.com>
>
>     "Give light, and the darkness will disappear of itself."
>     -- Desiderius Erasmus
>
>

Markdown (was Re: [foray] Tail position)

From:
Charlie Griefer
Date:
2013-05-09 @ 05:40
On May 8, 2013, at 10:36 PM, Sean Williamson 
<supernullset@wereprobablywrong.com> wrote:

> Nice explanation Sean!
> 
> Sidenote, would anyone be opposed to writing at least code examples in a
markdown syntax?
> 
> eg: 
> 
> ```clojure
> (defn f [x] (if x (recur x) (recur x)))
> ```
> 
> This would be so we can style the mailing list archives going forward; I
think it may be worth thinking about as we all get into more complicated 
code examples.

Being lazy here (not really… just spread thin with multi-tasking at the 
moment)… does Apple's Mail.app support markdown? Sounds like a good idea, 
and I'm all for it. Just not sure if I can actually comply :)

Charlie

Re: Markdown (was Re: [foray] Tail position)

From:
Sean Chalmers
Date:
2013-05-09 @ 05:41
I don't believe gmail supports it, I'd love to use it but I'm not sure I
can comply either... maybe fall back on gists?


On Thu, May 9, 2013 at 3:40 PM, Charlie Griefer <charlie@griefer.com> wrote:

>
> On May 8, 2013, at 10:36 PM, Sean Williamson <
> supernullset@wereprobablywrong.com> wrote:
>
> > Nice explanation Sean!
> >
> > Sidenote, would anyone be opposed to writing at least code examples in a
> markdown syntax?
> >
> > eg:
> >
> > ```clojure
> > (defn f [x] (if x (recur x) (recur x)))
> > ```
> >
> > This would be so we can style the mailing list archives going forward; I
> think it may be worth thinking about as we all get into more complicated
> code examples.
>
> Being lazy here (not really… just spread thin with multi-tasking at the
> moment)… does Apple's Mail.app support markdown? Sounds like a good idea,
> and I'm all for it. Just not sure if I can actually comply :)
>
> Charlie
>

Re: Markdown (was Re: [foray] Tail position)

From:
Sean Williamson
Date:
2013-05-09 @ 05:47
Gists are probably a more useable solution.

Let's just try to prefix a gist link with something like: `GIST::` or 
the like. Something that is easily machine findable in the archives.

Thoughts?

On 5/8/13 10:41 PM, Sean Chalmers wrote:
> I don't believe gmail supports it, I'd love to use it but I'm not sure 
> I can comply either... maybe fall back on gists?
>
>
> On Thu, May 9, 2013 at 3:40 PM, Charlie Griefer <charlie@griefer.com 
> <mailto:charlie@griefer.com>> wrote:
>
>
>     On May 8, 2013, at 10:36 PM, Sean Williamson
>     <supernullset@wereprobablywrong.com
>     <mailto:supernullset@wereprobablywrong.com>> wrote:
>
>     > Nice explanation Sean!
>     >
>     > Sidenote, would anyone be opposed to writing at least code
>     examples in a markdown syntax?
>     >
>     > eg:
>     >
>     > ```clojure
>     > (defn f [x] (if x (recur x) (recur x)))
>     > ```
>     >
>     > This would be so we can style the mailing list archives going
>     forward; I think it may be worth thinking about as we all get into
>     more complicated code examples.
>
>     Being lazy here (not really… just spread thin with multi-tasking
>     at the moment)… does Apple's Mail.app support markdown? Sounds
>     like a good idea, and I'm all for it. Just not sure if I can
>     actually comply :)
>
>     Charlie
>
>

Re: Markdown (was Re: [foray] Tail position)

From:
Sean Chalmers
Date:
2013-05-09 @ 05:46
Sounds like a delicious plan !

I really wish Gmail did support markdown goodness though, might see if I
can google lab it in Clojure.. *evil chuckle*


On Thu, May 9, 2013 at 3:47 PM, Sean Williamson <
supernullset@wereprobablywrong.com> wrote:

>  Gists are probably a more useable solution.
>
> Let's just try to prefix a gist link with something like: `GIST::` or the
> like. Something that is easily machine findable in the archives.
>
> Thoughts?
>
>
> On 5/8/13 10:41 PM, Sean Chalmers wrote:
>
> I don't believe gmail supports it, I'd love to use it but I'm not sure I
> can comply either... maybe fall back on gists?
>
>
> On Thu, May 9, 2013 at 3:40 PM, Charlie Griefer <charlie@griefer.com>wrote:
>
>>
>> On May 8, 2013, at 10:36 PM, Sean Williamson <
>> supernullset@wereprobablywrong.com> wrote:
>>
>> > Nice explanation Sean!
>> >
>> > Sidenote, would anyone be opposed to writing at least code examples in
>> a markdown syntax?
>> >
>> > eg:
>> >
>> > ```clojure
>> > (defn f [x] (if x (recur x) (recur x)))
>> > ```
>> >
>> > This would be so we can style the mailing list archives going forward;
>> I think it may be worth thinking about as we all get into more complicated
>> code examples.
>>
>> Being lazy here (not really… just spread thin with multi-tasking at the
>> moment)… does Apple's Mail.app support markdown? Sounds like a good idea,
>> and I'm all for it. Just not sure if I can actually comply :)
>>
>> Charlie
>>
>
>
>

Re: [foray] Tail position

From:
Ali Baitam
Date:
2013-05-09 @ 05:31
I get now. Thanks to both of you.


On Thu, May 9, 2013 at 1:29 AM, Sean Corfield <sean@corfield.org> wrote:

> Since Clojure rejects recur in a position that isn't the tail, you can
> conduct a quick experiment:
>
> (defn f [x] (if x (recur x) (recur x)))
>
> Clojure accepts this so both the 'then' and the 'else' expressions are
> considered tail position - because the whole 'if' is tail position (and
> 'if' is a special form, not a function call)..
>
> Clojure doesn't accept this - as Charlie indicated:
>
> (defn f [x] (if x (recur x) (- (recur x))))
>
> The else expression would be tail position but a subexpression of a
> function call is not.
>
> Sean
>
>
> On Wed, May 8, 2013 at 9:56 PM, Charlie Griefer <charlie@griefer.com>wrote:
>
>> On May 8, 2013, at 9:44 PM, Ali Baitam <abaitam@gmail.com> wrote:
>>
>> Thanks Charlie. I understand that a tail position is a point where the
>> function returns. But is it the point where it "will" return (the whole if)
>> which means a function can have one tail position and one recur can be
>> used. Or is it "might" return which is either the "then" clause or the
>> whole (- x) in the "else" clause? thus a function have more than one tail
>> position and recur can appear in many places? I wish the author used a
>> better function (with recur) to beter explain tail position.
>>
>>
>> Yeah, that might not be the best example for recur, but I imagine w e'll
>> get into it more deeply in chapter 7. For right now, the authors are just
>> trying to provide a gentle introduction to a lot of concepts.
>>
>> I think that while the entire (if… ) can be considered to be in tail
>> position, you're right… in this particular example there'd be no reason to
>> recur from it. Not that I can tell, anyway. And given that they were
>> demonstrating tail position specifically for the purpose of defining it as
>> the one restriction towards recur, you'd think they'd have actually shown a
>> function with recur :)
>>
>> So my take-away at this point is… you _can_ have more than one tail
>> position, and I'd wager that you _can_ recur from any of them. But of
>> course you don't necessarily have to.
>>
>>  --
>> Charlie Griefer
>> <http://charlie.griefer.com>http://charlie.griefer.com
>>
>> "Give light, and the darkness will disappear of itself."
>> -- Desiderius Erasmus
>>
>>
>