Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Adding features does not necessarily increase functionality -- it just makes the manuals thicker.


devel / comp.unix.programmer / To understand recursion, you first need to understand recursion (and Joey Hess obviously doesn't)

SubjectAuthor
* To understand recursion, you first need to understand recursion (and Joey Hess oRainer Weikusat
`* Re: To understand recursion, you first need to understand recursion (and Joey HeGeoff Clare
 +- Re: To understand recursion, you first need to understand recursion (and Joey HeGeoff Clare
 `- Re: To understand recursion, you first need to understand recursion (and Joey HeRainer Weikusat

1
To understand recursion, you first need to understand recursion (and Joey Hess obviously doesn't)

<87fry6ncqb.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11194&group=comp.unix.programmer#11194

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: To understand recursion, you first need to understand recursion (and Joey Hess obviously doesn't)
Date: Mon, 05 Feb 2024 15:37:48 +0000
Lines: 55
Message-ID: <87fry6ncqb.fsf@doppelsaurus.mobileactivedefense.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net oU9QcalrPwdlI6eyA8cAygfnySILvcLvAdWcCIpl7i4YxYPr8=
Cancel-Lock: sha1:Hl852OJBKEJ8yQomEM5N+2oe2Bg= sha1:7VZ4fMaE513ySbAAqZXxlvOlp+s= sha256:JK53tc6H+B9v5rOCeW7w3eQ3OBMTG4uPXmZ0fYXxeCA=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Mon, 5 Feb 2024 15:37 UTC

Debian (and derived distros) use a system called Debconf for prompting
users for configuration information during package installation. In the
advanced section, the manpage suggests that config scripts should support
moving backwards through multiple question so that users can fix mistakes
and then states

There are several ways to write the control structures of your
program so it can jump back to previous questions when
necessary. You can write goto-laden spaghetti code. Or you can
create several functions and use recursion. But perhaps the
cleanest and easiest way is to construct a state machine. Here is
a skeleton of a state machine that you can fill out and expand.

This is followed by a 40 line code example using case (Bourne shell) to
implement a form of computed goto in a loop with lots of explicit state
handling and switching code.

Considering the problem, there's a set of questions which needs to be
asked in order. If a user OKs an answer, the next question should be
asked, if he cancels it, the previous question should be asked
again. This absolutely cries for a recursive solution and there's a
really simple and general one which needs much less code than the
example in the manpage.

First, define a helper function for actually asking a question:

ask()
{ db_input high "$PREFIX/$1"
db_go
}

Given that, a function for asking a set of question which can back up to
the previous one can be written as

ask_all()
( # run in forked subshell so that variables are local

# termination condition: called w/ no argumnets,
# ergo, nothing to do, return success
test "$1" || return 0

# remove our question from argument list
q="$1"
shift

while true;
do
# ask question, return failure on failure (2 arbitrary)
ask "$q" || return 2

# invoke ask_all again to ask remaining question, return success on success
ask_all "$@" && return 0
done
)

Re: To understand recursion, you first need to understand recursion (and Joey Hess obviously doesn't)

<5sp99k-2qm.ln1@ID-313840.user.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11240&group=comp.unix.programmer#11240

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.bbs.nz!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: geo...@clare.See-My-Signature.invalid (Geoff Clare)
Newsgroups: comp.unix.programmer
Subject: Re: To understand recursion, you first need to understand recursion
(and Joey Hess obviously doesn't)
Date: Tue, 6 Feb 2024 13:47:17 +0000
Lines: 26
Message-ID: <5sp99k-2qm.ln1@ID-313840.user.individual.net>
References: <87fry6ncqb.fsf@doppelsaurus.mobileactivedefense.com>
Reply-To: netnews@gclare.org.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net kImp4Xg0BYOYppML3jcd8QZEymwdhTUy9RCt8Juk1C33qbEGpk
X-Orig-Path: ID-313840.user.individual.net!not-for-mail
Cancel-Lock: sha1:bUrUyRjFUKELsUdfNVZfzO1Xpk4= sha256:bFM6OCAJ6wgKR5vik5Xe9mLpUXru+JAn9iS4oDy2TkI=
User-Agent: Pan/0.154 (Izium; 517acf4)
 by: Geoff Clare - Tue, 6 Feb 2024 13:47 UTC

Rainer Weikusat wrote:

> # termination condition: called w/ no argumnets,
> # ergo, nothing to do, return success
> test "$1" || return 0

Nit-pick: the comment doesn't match the code. Should be either:

# termination condition: called w/ no arguments,
# ergo, nothing to do, return success
test "$#" -eq 0 || return 0

or:

# termination condition: called w/ no arguments or with an
# empty first argument, ergo, nothing to do, return success
test "$1" || return 0

In the latter case I would also usually use test -n "$1" just in
case it ever gets run with a version of test that doesn't follow
the POSIX single-argument rule correctly. (I believe pre-POSIX
Bourne shells when given test "!" would produce an error complaining
of a missing argument.)

--
Geoff Clare <netnews@gclare.org.uk>

Re: To understand recursion, you first need to understand recursion (and Joey Hess obviously doesn't)

<3as99k-hvn.ln1@ID-313840.user.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11242&group=comp.unix.programmer#11242

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: geo...@clare.See-My-Signature.invalid (Geoff Clare)
Newsgroups: comp.unix.programmer
Subject: Re: To understand recursion, you first need to understand recursion
(and Joey Hess obviously doesn't)
Date: Tue, 6 Feb 2024 14:28:51 +0000
Lines: 20
Message-ID: <3as99k-hvn.ln1@ID-313840.user.individual.net>
References: <87fry6ncqb.fsf@doppelsaurus.mobileactivedefense.com>
<5sp99k-2qm.ln1@ID-313840.user.individual.net>
Reply-To: netnews@gclare.org.uk
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net hMF9ZFzfHUdFunnxwqC4DwNS1cFndwxslnb+1FgdYbXuWcJPB5
X-Orig-Path: ID-313840.user.individual.net!not-for-mail
Cancel-Lock: sha1:oz5OaT/fl/HEu45M0+xHwvS7aAI= sha256:R2zMtaP6BuWWZ7tEkVYjMCdjpDDTd02Q4zoAASEaj6A=
User-Agent: Pan/0.154 (Izium; 517acf4)
 by: Geoff Clare - Tue, 6 Feb 2024 14:28 UTC

Geoff Clare wrote:

> # termination condition: called w/ no arguments,
> # ergo, nothing to do, return success
> test "$#" -eq 0 || return 0

What's that law about posts pointing out mistakes always containing
a mistake?

I failed to notice the new test has the logic the other way round
from test "$1". So it should be:

test "$#" -eq 0 && return 0

or:

test "$#" -ne 0 || return 0

--
Geoff Clare <netnews@gclare.org.uk>

Re: To understand recursion, you first need to understand recursion (and Joey Hess obviously doesn't)

<87ttml7dfh.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11247&group=comp.unix.programmer#11247

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: To understand recursion, you first need to understand recursion (and Joey Hess obviously doesn't)
Date: Tue, 06 Feb 2024 16:41:38 +0000
Lines: 24
Message-ID: <87ttml7dfh.fsf@doppelsaurus.mobileactivedefense.com>
References: <87fry6ncqb.fsf@doppelsaurus.mobileactivedefense.com>
<5sp99k-2qm.ln1@ID-313840.user.individual.net>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net TZCzyxlAXKqKGuMXJbcYXA8YxqN+zCj378dST0MDbsfaNDLuI=
Cancel-Lock: sha1:fi/RHiY/fcMwQTtm/QUb8XeyoMc= sha1:M/zxfQJEOHeXWfeuSMorbPci4AM= sha256:7/bNiRo1CexF+UKEMu3jjuMrqNoF9Z5yw9KRLDitZJY=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Tue, 6 Feb 2024 16:41 UTC

Geoff Clare <geoff@clare.See-My-Signature.invalid> writes:
> Rainer Weikusat wrote:
>
>> # termination condition: called w/ no argumnets,
>> # ergo, nothing to do, return success
>> test "$1" || return 0
>
> Nit-pick: the comment doesn't match the code. Should be either:
>
> # termination condition: called w/ no arguments,
> # ergo, nothing to do, return success
> test "$#" -eq 0 || return 0
>
> or:
>
> # termination condition: called w/ no arguments or with an
> # empty first argument, ergo, nothing to do, return success
> test "$1" || return 0

In theory, that's correct. In practice, passing empty arguments to this
functions serves no useful purpose, hence, that's something the calling
code isn't supposed to do. I've also just inserted the comments to
explain the example, they're not in the actual code.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor