Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #96: Vendor no longer supports the product


comp / comp.lang.lisp / Re: applying f to f n times - best argument order?

SubjectAuthor
* Re: applying f to f n times - best argument order?B. Pym
`* Re: applying f to f n times - best argument order?Jeff Barnett
 `- Re: applying f to f n times - best argument order?Madhu

1
Subject: Re: applying f to f n times - best argument order?
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 25 Aug 2024 10:04 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: applying f to f n times - best argument order?
Date: Sun, 25 Aug 2024 10:04:49 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <vaevk0$1rhmq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 25 Aug 2024 12:04:50 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d36c7c262f681e9927de6a038d93638b";
logging-data="1951450"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cgL5eWlMefzq6hdhFR3C2"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:05z1Dni0zKlIzt0R4HcOiA7IdHg=
View all headers

Kaz Kylheku wrote:

> You want to bounce the arguments down into the recursive call, not a
> list of them as one argument, right?
>
> Is this what you are looking for:
>
> (defun ncall (f n &rest data)
> (loop repeat n
> for result = (apply f data) then (funcall f result)
> finally (return result)))
(define (feedback func init bottom-i :optional (top-i #f))
(let ((result init))
(if top-i
(do ((i bottom-i (+ 1 i)))
((> i top-i) result)
(set! result (func result i)))
(dotimes (i bottom-i)
(set! result (func result))))
result))

;; factorial
(feedback (lambda (prod i) (* i prod)) 1 1 5)
===>
120

(feedback (lambda (prod) (* 2 prod)) 1 8)
===>
256

;; Newton square root
(let ((x 99.0))
(feedback
(lambda (guess) (/. (+ guess (/. x guess)) 2.0))
1.0 8))
===>
9.9498743710662

(sqrt 99)
===>
9.9498743710662

Subject: Re: applying f to f n times - best argument order?
From: Jeff Barnett
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 25 Aug 2024 18:50 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jbb@notatt.com (Jeff Barnett)
Newsgroups: comp.lang.lisp
Subject: Re: applying f to f n times - best argument order?
Date: Sun, 25 Aug 2024 12:50:21 -0600
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <vafudd$220kj$1@dont-email.me>
References: <vaevk0$1rhmq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 25 Aug 2024 20:50:22 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="6fac08669db3d5a6a4728f4eb7d7d9ce";
logging-data="2163347"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18z3j8HfH+BY2VQjrkfrBj37ZerMLFBQGY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:aLoO2QfAByYCk+ANZ+IVIX/giyI=
X-Antivirus-Status: Clean
X-Antivirus: AVG (VPS 240825-2, 8/25/2024), Outbound message
Content-Language: en-US
In-Reply-To: <vaevk0$1rhmq$1@dont-email.me>
View all headers

On 8/25/2024 4:04 AM, B. Pym wrote:
> Kaz Kylheku wrote:
>
>> You want to bounce the arguments down into the recursive call, not a
>> list of them as one argument, right?
>>
>> Is this what you are looking for:
>>
>> (defun ncall (f n &rest data)
>> (loop repeat n
>> for result = (apply f data) then (funcall f result)
>> finally (return result)))
>
> (define (feedback func init bottom-i :optional (top-i #f))
> (let ((result init))
> (if top-i
> (do ((i bottom-i (+ 1 i)))
> ((> i top-i) result)
> (set! result (func result i)))
> (dotimes (i bottom-i)
> (set! result (func result))))
> result))

Isn't this where you usually jump in and loudly proclaim "SHORTER!"? You
might as well repeat it hear since you are not shorter a significant
amount of the time.

Off topic question: Any job offers recently?

> ;; factorial
> (feedback (lambda (prod i) (* i prod)) 1 1 5)
> ===>
> 120
>
>
> (feedback (lambda (prod) (* 2 prod)) 1 8)
> ===>
> 256
>
>
> ;; Newton square root
> (let ((x 99.0))
> (feedback
> (lambda (guess) (/. (+ guess (/. x guess)) 2.0))
> 1.0 8))
> ===>
> 9.9498743710662
>
> (sqrt 99)
> ===>
> 9.9498743710662
--
Jeff Barnett

Subject: Re: applying f to f n times - best argument order?
From: Madhu
Newsgroups: comp.lang.lisp
Organization: Motzarella
Date: Mon, 26 Aug 2024 05:04 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: enometh@meer.net (Madhu)
Newsgroups: comp.lang.lisp
Subject: Re: applying f to f n times - best argument order?
Date: Mon, 26 Aug 2024 10:34:31 +0530
Organization: Motzarella
Lines: 5
Message-ID: <m3ed6b7u3k.fsf@leonis4.robolove.meer.net>
References: <vaevk0$1rhmq$1@dont-email.me> <vafudd$220kj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Mon, 26 Aug 2024 07:04:45 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="bc32bf7eee8b8ce76f88772c6869d249";
logging-data="2460798"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+TrhLRJCpLatI7LAZnXGWbGUBxaajgLIo="
Cancel-Lock: sha1:AVSpYyu9CJFpbO+JP8iVrh7gStE=
sha1:YzYq219jNojdJPRYS3OEzfWgLhw=
X-No-Archive: yes
View all headers

memo: there's no glory in trolling WJ

* Jeff Barnett <vafudd$220kj$1@dont-email.me> :
Wrote on Sun, 25 Aug 2024 12:50:21 -0600:

1

rocksolid light 0.9.8
clearnet tor