Except, I don't want to use eval or do. You're missing the fact that this is a QA application.
Well, if you reread the original post at the top of the
thread, it is QA people who will be using this. They
aren't programmers, but presumably they know how to
do QA. If not, the company has problems that inventing
a scripting language won't solve.
As for Turing-completeness, I might be wrong, but I believe that GOTO, JZ, and JNZ are the minimal requirements for Turing completeness
It depends. Turing-completeness is about equivalence,
not a specific implementation. Unlambda is Turing
complete but does not provide GOTO or anything like
it, really. (All the work in Unlambda is done by
combining and applying functions.) Pascal does not
provide GOTO and is certainly Turing complete.
I don't think Befunge provides GOTO; it handles
control flow by changing directions, not positions.
Hofstadter
argues convincingly that sufficiently
powerful formal systems in math (e.g., Typographical
Number Theory or Principia Mathematica) are
Turing-equivalent.update: No, wait,
that's not right. TNT represents all primitive
recursive truths, but not all general recursive
truths. I was momentarily
confused. P.M. is probably similar.
It is, however, almost certainly possible to
construct a Turing equivalent formal system.
Also, I do not see why both JZ and JNZ should be
required;
they are, as near as I can determine, equivalent;
at _least_ they are equivalent if you also have
GOTO, because
a JNZ followed by a GOTO is equivalent to a JZ, and
a JZ followed by a GOTO is equivalent to a JNZ.
However, a decision mechanism of some kind (what I
called "conditionals") is needed. JZ and JNZ can
provide this. In Perl we use (among other things)
if. I suspect, however, that conditionals are a
feature the QA people in question (who don't want
to learn Perl) won't need, at least, not initially.
All they really want to do, as I understand it, is
call a series of prefabricated procedures that the
OP is going to write.
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
| [reply] [d/l] |
GOTO as a keyword doesn't need to be provided for GOTO as functionality to exist. Whenever you call a subroutine, some form of GOTO activity occurs. Whenever you do a conditional, GOTO occur. For example, a simple if-statement can break down to the following:
if ($x) {
statement1
}
else
{
statement2
}
--------
JZ $x ELSE1
statement1
JMP IF1_DONE
ELSE1:
statement2
IF1_DONE:
(JMP used in place of GOTO, to continue the ASM-style operators.)
Every if-statement is equivalent to the above ASM-style layout. while and for are similarly rewritable (and, in days gone by, would have been rewritten to exactly that in the ASM equivalent, at least for x86 and PDP-11, which are the only ASMs I'm familiar with). All subroutine calls (which is Unlambda) are performed by GOTO-type functionality.
------
We are the carpenters and bricklayers of the Information Age.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
| [reply] [d/l] |
GOTO as a keyword doesn't need to be provided for GOTO as functionality to exist.
No, that's certainly true. All you need is something
that is substitutable for GOTO. This may be a single
feature that by itself is isomorphic to GOTO (which
can range from the obvious (JMP) to the slightly
less obvious (COME FROM), or it
may be a set of features that can be grouped together
to accomplish the things that GOTO can also be used
(in combination with its helper instructions) to
accomplish. The latter kind of isomorphism is more
interesting, because there is no direct counterpart
for GOTO per se, but its functionality is covered
anyway. In this case, the mapping is at a higher
level than the individual instruction.
Whenever you call a subroutine, some form of GOTO activity occurs.
This is generally true, though in theory it would not
necessarily have to be. Most CPU instruction sets
are designed with a certain traditional set of
instructions, usually including near and far (or
relative and absolute) unconditional jumps, and so
computer languages compiled to those processors of
course boil down to using GOTO for stuff. It seems
to be easiest for the lowlevel programmers who
implement microcode and assembly languages to think
this way, either because it's what they were trained
in and know, or perhaps for some other, more inherent
reason. But having played around just a little with
electronic circuits (oscillators and things) I can
imagine other possible ways for things to be. It
would be possible, for example, to manipulate control
by turning various gates on and off. Some other
operations would be needed for Turing equivalence,
but for that matter GOTO by itself doesn't cut it
either.
All subroutine calls (which is Unlambda) are performed by GOTO-type functionality.
You could as well say that all hash lookups in Perl
are performed by GOTO-type functionality, since
I'm sure a jump instruction gets executed by the
CPU at some point duing the process. As far as
I can understand the way Unlambda does things
(which, admittedly, is limited), there
is no subroutine calling per se, as far as I can
determine; there are
subroutine combinators and subroutine application,
but I'm not at all sure that either of them by
itself is directly analagous to a subroutine call,
though my understanding of the language is limited.
However, they add up to being able to do the same
things that can be done with other paradigms, such
as subroutine definition and calling. (Incidentally,
I'm fairly sure that Unlambda has nothing
directly analagous to subroutine definition in
the usual sense, which
is part of the reason I suspect it doesn't have an
analogue for calling either, since the two normally
go hand in hand. If you know otherwise, I'd be
interested in an explanation of how this works,
as I've been reading up on Scheme and as a result
am becomming intrigued somewhat by Unlambda. As
near as I can determine, Unlambda functions are
as much like data as like code.)
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
| [reply] [d/l] |