Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Been through Hell? Whaddya bring back for me?" -- A. Brilliant


devel / comp.lang.lisp / Re: .Re: Illegal LOOP usage?

SubjectAuthor
* .Re: Illegal LOOP usage?Robert L.
`* Re: .Re: Illegal LOOP usage?steve gonedes
 `* Re: .Re: Illegal LOOP usage?Kaz Kylheku
  `- Re: .Re: Illegal LOOP usage?Steve G

1
.Re: Illegal LOOP usage?

<t1o1eg$1js4$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16999&group=comp.lang.lisp#16999

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!OqeOGrcX7oT7c14m3RGjKw.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: Illegal LOOP usage?
Date: Sat, 26 Mar 2022 21:43:45 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t1o1eg$1js4$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="53124"; posting-host="OqeOGrcX7oT7c14m3RGjKw.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, 26 Mar 2022 21:43 UTC

Edi Weitz wrote:

> So, this function from Drakma
>
> (defun split-string (string &optional (separators " ,-"))
> "Splits STRING into substrings separated by the characters in the
> sequence SEPARATORS. Empty substrings aren't collected."
> (loop for char across string
> when (find char separators :test #'char=)
> when collector
> collect (coerce collector 'string) into result
> and do (setq collector nil) end
> else
> collect char into collector
> finally (return (if collector
> (append result (list (coerce collector 'string)))
> result))))
>
> works as intended with LispWorks, but doesn't work with AllegroCL or
> SBCL. It seems the latter two simply ignore the (SETQ COLLECTOR NIL)
> form. My guess is that the code above is somehow incorrect in that it
> modifies a variable which is used in a "collect ... into ..." clause,
> but I couldn't find anything in the CLHS that explicitly says so.
>
> Any hints?

In "ANSI Common Lisp", Paul Graham makes the following comments:

The loop macro was originally designed to help inexperienced
Lisp users write iterative code. Instead of writing Lisp code,
you express your program in a form meant to resemble English,
and this is then translated into Lisp. Unfortunately, loop is
more like English than its designers ever intended: you can
use it in simple cases without quite understanding how it
works, but to understand it in the abstract is almost
impossible.
....
the ANSI standard does not really give a formal specification
of its behavior.
....
The first thing one notices about the loop macro is that it
has syntax. A loop expression contains not subexpressions but
clauses. The clauses are not delimited by parentheses;
instead, each kind has a distinct syntax. In that, loop
resembles traditional Algol-like languages. But the other
distinctive feature of loop, which makes it as unlike Algol as
Lisp, is that the order in which things happen is only
loosely related to the order in which the clauses occur.
....
For such reasons, the use of loop cannot be recommended.

Re: .Re: Illegal LOOP usage?

<56b46b2b-031e-4f4c-bc6b-3fcb725d5de6n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17007&group=comp.lang.lisp#17007

  copy link   Newsgroups: comp.lang.lisp
X-Received: by 2002:a05:6214:cc3:b0:440:f5fc:f1ab with SMTP id 3-20020a0562140cc300b00440f5fcf1abmr30242490qvx.59.1648648744164;
Wed, 30 Mar 2022 06:59:04 -0700 (PDT)
X-Received: by 2002:a05:6870:d191:b0:dd:a91e:82dc with SMTP id
a17-20020a056870d19100b000dda91e82dcmr2184388oac.248.1648648743839; Wed, 30
Mar 2022 06:59:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!border1.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.lisp
Date: Wed, 30 Mar 2022 06:59:03 -0700 (PDT)
In-Reply-To: <t1o1eg$1js4$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=184.102.120.193; posting-account=J7s-KQoAAABxnJDbN-3ZlYayYdnHhWkr
NNTP-Posting-Host: 184.102.120.193
References: <t1o1eg$1js4$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <56b46b2b-031e-4f4c-bc6b-3fcb725d5de6n@googlegroups.com>
Subject: Re: .Re: Illegal LOOP usage?
From: sgonedes1977@gmail.com (steve gonedes)
Injection-Date: Wed, 30 Mar 2022 13:59:04 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 57
 by: steve gonedes - Wed, 30 Mar 2022 13:59 UTC

On Saturday, March 26, 2022 at 5:43:50 PM UTC-4, Robert L. wrote:
> Edi Weitz wrote:
>
> > So, this function from Drakma
> >
> > (defun split-string (string &optional (separators " ,-"))
> > "Splits STRING into substrings separated by the characters in the
> > sequence SEPARATORS. Empty substrings aren't collected."
> > (loop for char across string
> > when (find char separators :test #'char=)
> > when collector
> > collect (coerce collector 'string) into result
> > and do (setq collector nil) end
> > else
> > collect char into collector
> > finally (return (if collector
> > (append result (list (coerce collector 'string)))
> > result))))


> In "ANSI Common Lisp", Paul Graham makes the following comments:
>
> The loop macro was originally designed to help inexperienced
> Lisp users write iterative code. Instead of writing Lisp code,

Oh please! NO!

The loop macro was designed to make code easier to read, write, and maintain; why else would it be in the ANSI standard?

(defun split-string-on-char-loop (string char)
"Return list of substrings without any empty substrings."
(loop for start = 0 then (+ end 1)
for end = (position char string :start start)
unless (eq start end)
collect (subseq string start end)
until (null end)))

(defun split-string-on-char-do (string char)
"Return list of substrings without any empty substrings.
This function uses the [DO*] function."
(let ((res () ))
(do* ((start 0 (1+ end))
(end (position char string :start start)
;; end will have bad type reference
(position char string :start start)))
((null end)
(nreverse (push (subseq string start) res)))
(unless (eql start end)
(push (subseq string start end) res)))))

Seriously which is easier to read? The do loop has bad type inferences due to position returning null or a number.

I hope this is a descent example of loop. There are better ways to make the code easier to read. The thing with loop is that it is a macro, computers are fast enough these
days so that you do not have to use GOTO statements anymore :)

Re: .Re: Illegal LOOP usage?

<20220331214727.523@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17009&group=comp.lang.lisp#17009

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: .Re: Illegal LOOP usage?
Date: Fri, 1 Apr 2022 06:35:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 180
Message-ID: <20220331214727.523@kylheku.com>
References: <t1o1eg$1js4$1@gioia.aioe.org>
<56b46b2b-031e-4f4c-bc6b-3fcb725d5de6n@googlegroups.com>
Injection-Date: Fri, 1 Apr 2022 06:35:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5b189a79a19927f2a80b70a11ec93a75";
logging-data="15279"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19YBbnII0xquNqwzIRWhDxmqsY/KDXTbiQ="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:i4x+oR+Csu+kmDmVK216BWhwEmU=
 by: Kaz Kylheku - Fri, 1 Apr 2022 06:35 UTC

On 2022-03-30, steve gonedes <sgonedes1977@gmail.com> wrote:
> (defun split-string-on-char-loop (string char)
> "Return list of substrings without any empty substrings."
> (loop for start = 0 then (+ end 1)
> for end = (position char string :start start)
> unless (eq start end)
> collect (subseq string start end)
> until (null end)))

I've been amusing myself with a little light side project: cppawk.

It's combining C preprocessing with Awk.

The result is amazing (not in absolute terms, but relative to the
necessarily low expectations one would naturally have of this sort of
thing).

I've built a loop macro with definable clauses, that is capable
of parallel as well as cross-producting iteration---and with
a combinator that can parallelize clauses in the cross-producting loop.

Without further ado, here is a translation of your loop.

$ ./cppawk '
#include <iter.h>

// User-defined loop clause: first_then
// Five macros must be defined according a naming scheme,
// all having the same arguments.

#define __init_first_then(var, first, then) (var = (first))
#define __test_first_then(var, first, then) 1
#define __prep_first_then(var, first, then) 1
#define __fini_first_then(var, first, then) 1
#define __step_first_then(var, first, then) (var = (then))

// User-defined loop-clause: for_var
// Just macro for first_then
#define for_var(var, expr) first_then(var, expr, expr)

// index function with start position

function index_from(str, ch, start,
sstr, pos)
{ sstr = substr(str, start)
pos = index(sstr, ch)
return pos ? pos + start - 1 : 0
}

// now our loop

function split_string_on_char_loop(string, char)
{ loop (first_then (start, 1, end + 1),
for_var (end, index_from(string, char, start)),
xcollect (out, (end ? substr(string, start, end - start)
: substr(string, start))),
while (end))
{ }
return out
}

// Test with awk loop
// N.B.! the nil object is "" (empty string)
// sexp("") -> "nil"
{ print sexp(split_string_on_char_loop($1, $2)) }'
, ,
(nil nil)
a, ,
("a" nil)
,a ,
(nil "a")
a,b,c ,
("a" "b" "c")

I had to add the xcollect clause because the regular collect does not
fire when the loop terminates. If the loop body executes 3 times,
collect will produce a list of 3 items. But xcollect will also collect
the expression one more time in spite of the failed loop guard.

I will likely roll the user-defined first_then and for_var into
the implementation also.

Difference between collect and xcollect:

#define __init_collect(var, expr) var = list_begin()
#define __test_collect(var, expr) 1
#define __prep_collect(var, expr) var = list_add(var, expr)
#define __fini_collect(var, expr) var = list_end(var)
#define __step_collect(var, expr) 1

#define __init_xcollect(var, expr) var = list_begin()
#define __test_xcollect(var, expr) 1
#define __prep_xcollect(var, expr) var = list_add(var, expr)
#define __fini_xcollect(var, expr) var = list_end(list_add(var, expr))
#define __step_xcollect(var, expr) 1

In the "fini" operator, we do one extra list_add.

It sort of blows me away how simple everything is, in spite of the
weakness of the C preprocessor. It can't do anything; you can't
calculate the rest of an argument list or execute any sort of looping
or mapping. Yet ...

Other examples:

Find the maximum position of a ball thrown upward with initial
velocity 5. Velocity decrements by 1 on each step.

#include <iter.h>

BEGIN {
loop (from_step (vel, 5, -1),
from_step (pos, 0, vel),
while (pos >= 0),
maximizing (maxpos, pos))
{
print pos
}
print "maxpos =", maxpos
}'

0
4 7
9 10
10
9 7
4 0
maxpos = 10

Cross-product loop with parallel clauses thanks to the "lockstep"
clause combinator:

#include <iter.h>

BEGIN {
$0 = "a b c" # set fields

split("X Y", arr) # init array

bags (b1, b2) {
loop_cross (lockstep(fields(f),
str(i, ch, "IJK")),
keys(ky, arr),
lockstep(range(j, 1, 3),
from(k, 100)))
{
print f, ch, arr[ky], j, k
bag(b1, j)
}
}

print sexp(b1)
}

a I X 1 100
a I X 2 101
a I X 3 102
a I Y 1 100
a I Y 2 101
a I Y 3 102
b J X 1 100
b J X 2 101
b J X 3 102
b J Y 1 100
b J Y 2 101
b J Y 3 102
c K X 1 100
c K X 2 101
c K X 3 102
c K Y 1 100
c K Y 2 101
c K Y 3 102
(1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3)

Re: .Re: Illegal LOOP usage?

<871qye5k3f.fsf@l0ft.tpl>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17022&group=comp.lang.lisp#17022

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 03 Apr 2022 09:16:14 -0500
From: Sgonedes1977@gmail.com (Steve G)
Newsgroups: comp.lang.lisp
Subject: Re: .Re: Illegal LOOP usage?
References: <t1o1eg$1js4$1@gioia.aioe.org>
<56b46b2b-031e-4f4c-bc6b-3fcb725d5de6n@googlegroups.com>
<20220331214727.523@kylheku.com>
Date: Sun, 03 Apr 2022 10:15:32 -0400
Message-ID: <871qye5k3f.fsf@l0ft.tpl>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:yUF9XzioUbz/IbrsQHUNsxf+NhM=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 8
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-EctR/BClWMkNdfoTcYmqzFMl6ehbG476EKYAX/raUDHCgTK6/wuRg7y6lvAPqw3YFBsUKPDN/6n/IuJ!4LyuDkZNjW7eh06O0a3tBwN/61TUgM895ukDsli8GvNYHSUn
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 1332
 by: Steve G - Sun, 3 Apr 2022 14:15 UTC

Kaz Kylheku <480-992-1380@kylheku.com> writes:

> [ ... ]
> It's combining C preprocessing with Awk.

If there is one thing I could add to C it would be a better
preprocessor. I would not be using awk for this - I would probably write
it in C.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor