TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

When is a recursive function not a recursive function?

31 pointsby r4umover 10 years ago

6 comments

lispmover 10 years ago
That&#x27;s the usual late-binding semantics for global functions in Lisp.<p>Note that in Common Lisp a compiler can assume that the recursive call is actually the same function:<p>&gt; Within a function named F, the compiler may (but is not required to) assume that an apparent recursive call to a function named F refers to the same definition of F, unless that function has been declared notinline. The consequences of redefining such a recursively defined function F while it is executing are undefined.
frou_dhover 10 years ago
I&#x27;ve always thought that in languages where functions are first-class, a function referring to itself via a name binding is strange, since the function is supposed to be a value just like any other. Values like 33 or the list of foo,&quot;bar&quot;,7.5 aren&#x27;t aware of which names (if any) are bound to themselves and that&#x27;s how it should be.<p>The so-called recur* in the post sounds like an improvement.
评论 #8412576 未加载
评论 #8412438 未加载
评论 #8412521 未加载
评论 #8412388 未加载
lisperover 10 years ago
TL;DR:<p>(defn foo baz)<p>does not mean the same thing as<p>(defn (foo n) (baz n)) == (defn foo (lambda (n) (baz n)))<p>because in the former case baz is dereferenced when foo is defined and in the latter case it&#x27;s dereferenced when foo is called. So in the former case, if baz changes between when foo is defined and when it is called, you&#x27;ll get surprising results.
kazinatorover 10 years ago
cdown is not &quot;no longer recursive&quot;!<p>It is either &quot;still recursive&quot; or &quot;never had been recursive&quot; depending on your point of view.<p>Evidence for &quot;still recursive&quot;: when you call it, the countdown is consed up.<p>Evidence for &quot;never had been recursive&quot;: nowhere in the code was there ever a call to cdown, other than the top-level one.<p>&gt; <i>(def cdown #&#x27;countdown) ... This works but is rather counterintuitive; with a Lisp-1 you get used to refering to functions directly rather than with a quoted symbol, but here we have to use both a quote and a #.</i><p>It is counterintuitive not because of Lisp-1 versus Lisp-2 but because in (def cdown countdown) the symbolic reference to the function countdown is immediately evaluated to an object that is bound to cdown, such that cdown doesn&#x27;t follow a redefinition of countdown. Yet, in (def cdown #&#x27;countdown), the #&#x27;countdown is deferred so that the countdown symbol is re-evaluated. This means that def has strange evaluation rules, or that #&#x27;countdown has nothing to do with the Common Lisp #&#x27;countdown: namely, it produces some kind of proxy object which resolves to a function, using late binding with a symbol that is captured in its innards. Or possibly #&#x27;countdown produces a wrapper function which takes the call and defers to countdown, by symbol. That&#x27;s what is &quot;counterintuitive&quot;: that countdown and #&#x27;countdown do not evaluate to the same thing based on experiences with some other dialect.
p4bl0over 10 years ago
This is a good example of why it is better to be lexically scoped (at least by default, with a possible way to escape that). But I would have thought that clo<i>j</i>ure would be. Is it really not?
评论 #8412086 未加载
shacharzover 10 years ago
Why would you alias your functions? I don&#x27;t write in clojure, but I haven&#x27;t encountered it in java&#x2F;javascript&#x2F;c++&#x2F;Matlab
评论 #8411850 未加载
评论 #8449187 未加载