Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Nature always sides with the hidden flaw.


devel / comp.lang.forth / .Re: Road to Clojure Survey 2.0

SubjectAuthor
* .Re: Road to Clojure Survey 2.0Robert L.
`* Re: .Re: Road to Clojure Survey 2.0Jali Heinonen
 `- Re: .Re: Road to Clojure Survey 2.0Hans Bezemer

1
.Re: Road to Clojure Survey 2.0

<t14akp$14q0$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17351&group=comp.lang.forth#17351

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!GE+8+L9ohIp2pD6PT3mH2Q.user.46.165.242.75.POSTED!not-for-mail
From: No_spamm...@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.forth
Subject: .Re: Road to Clojure Survey 2.0
Date: Sat, 19 Mar 2022 10:18:04 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t14akp$14q0$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="37696"; posting-host="GE+8+L9ohIp2pD6PT3mH2Q.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Sat, 19 Mar 2022 10:18 UTC

> than version you've wrote in CL. i would write it like this:
>
> (defun factorial (n)
> (loop with p = 1
> for i from 1 to n
> do (setf p (* p i))
> finally (return p)))
>
> IMHO that's cleaner. or if i absolutely must use recursion:

Gauche Scheme (using lazy iota):

(define (fac n) (fold * 1 (liota n 1)))

(fac 6)
===>
720

(fac 5)
===>
120

In Forth?

Re: .Re: Road to Clojure Survey 2.0

<043ed234-ac20-4b97-84da-aa885be08c28n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17354&group=comp.lang.forth#17354

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:622a:508:b0:2e1:deae:22bd with SMTP id l8-20020a05622a050800b002e1deae22bdmr10454655qtx.597.1647698312160;
Sat, 19 Mar 2022 06:58:32 -0700 (PDT)
X-Received: by 2002:a05:622a:1906:b0:2e0:77a7:16c4 with SMTP id
w6-20020a05622a190600b002e077a716c4mr10948877qtc.119.1647698311893; Sat, 19
Mar 2022 06:58:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!pasdenom.info!usenet-fr.net!fdn.fr!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 19 Mar 2022 06:58:31 -0700 (PDT)
In-Reply-To: <t14akp$14q0$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=87.95.69.6; posting-account=kiOBZQoAAADFsAs31ZHaefxTuQxv84Wm
NNTP-Posting-Host: 87.95.69.6
References: <t14akp$14q0$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <043ed234-ac20-4b97-84da-aa885be08c28n@googlegroups.com>
Subject: Re: .Re: Road to Clojure Survey 2.0
From: jali.hei...@gmail.com (Jali Heinonen)
Injection-Date: Sat, 19 Mar 2022 13:58:32 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Jali Heinonen - Sat, 19 Mar 2022 13:58 UTC

lauantai 19. maaliskuuta 2022 klo 12.18.06 UTC+2 Robert L. kirjoitti:
> > than version you've wrote in CL. i would write it like this:
> >
> > (defun factorial (n)
> > (loop with p = 1
> > for i from 1 to n
> > do (setf p (* p i))
> > finally (return p)))
> >
> > IMHO that's cleaner. or if i absolutely must use recursion:
>
> Gauche Scheme (using lazy iota):
>
> (define (fac n) (fold * 1 (liota n 1)))
>
> (fac 6)
> ===>
> 720
>
> (fac 5)
> ===>
> 120
>
> In Forth?

8th includes factorial inside the library:

needs math/factorial

6 n:! . cr
5 n:! . cr

I have a challenge for you:

\
\ Fibonacci with million digits for the 8th programming language
\ : bits? \ n -- nbits-1
n:ln 2 n:ln n:/ n:int ;

: fiboloop
>r 2dup 2 n:*
over n:-
n:* -rot
n:sqr swap n:sqr n:+
r> r@ swap n:shr 1 n:band if
dup rot n:+
then ;

: fibo \ n -- fibo(n)
>r F0 F1
' fiboloop 1 r@ bits? loop-
r> 1 n:band if
n:sqr swap n:sqr n:+
else
2 n:* over n:- n:*
then ;

: app:main
1000000 n#
4784969 fibo
"%.f" strfmt \ Convert result to just an 'int' string.
s:len . " digits:" . cr
dup 40 s:lsub . " upper 40 digits" . cr
40 s:rsub . " lower 40 digits" . cr ;

In Scheme?

Re: .Re: Road to Clojure Survey 2.0

<34cc60fb-d04c-420a-b3e7-43fd88c921efn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17358&group=comp.lang.forth#17358

  copy link   Newsgroups: comp.lang.forth
X-Received: by 2002:a05:620a:2586:b0:67b:1141:ce24 with SMTP id x6-20020a05620a258600b0067b1141ce24mr8725368qko.542.1647700022399;
Sat, 19 Mar 2022 07:27:02 -0700 (PDT)
X-Received: by 2002:a05:6214:1cc2:b0:435:7195:784f with SMTP id
g2-20020a0562141cc200b004357195784fmr10332748qvd.59.1647700022243; Sat, 19
Mar 2022 07:27:02 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.forth
Date: Sat, 19 Mar 2022 07:27:02 -0700 (PDT)
In-Reply-To: <043ed234-ac20-4b97-84da-aa885be08c28n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=82.95.228.79; posting-account=Ebqe4AoAAABfjCRL4ZqOHWv4jv5ZU4Cs
NNTP-Posting-Host: 82.95.228.79
References: <t14akp$14q0$1@gioia.aioe.org> <043ed234-ac20-4b97-84da-aa885be08c28n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <34cc60fb-d04c-420a-b3e7-43fd88c921efn@googlegroups.com>
Subject: Re: .Re: Road to Clojure Survey 2.0
From: the.beez...@gmail.com (Hans Bezemer)
Injection-Date: Sat, 19 Mar 2022 14:27:02 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 21
 by: Hans Bezemer - Sat, 19 Mar 2022 14:27 UTC

On Saturday, March 19, 2022 at 2:58:33 PM UTC+1, Jali Heinonen wrote:
Fastest factorial in the world (32bit and 64bit) :

create (factorial)
1 , 1 , 2 , 6 , 24 , 120 , 720 , 5040 , 40320 , 362880 , 3628800 ,
39916800 , 479001600 ,

/cell 4 - [IF] \ 64bit version
20 constant max-factorial

6227020800 , 87178291200 , 1307674368000 , 20922789888000 , 355687428096000 ,
6402373705728000 , 121645100408832000 , 2432902008176640000 ,
[ELSE]

12 constant max-factorial \ 32bit version
[THEN]

: factorial max-factorial min cells (factorial) + @c ;

... and still only 25 opcodes (4tH 64bits)!

Hans Bezemer

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor