There's a programming exercise on Exercism called two-fer. It takes an optional parameter. If the parameter is absent it returns "One for you, one for me."It is impossible.
If the parameter is present it is interpolated into the string in place of the "you".
As I understand it, and i'm no Forth programmer, optional items aren't a thing in
Forth. Rather, you either program for something or program for nothing. Thus, a two-fer word would expect a null-string or maybe even a null.
Am I understanding this right?
Bruce.
In article <debd1ce9-7e04-4145...@googlegroups.com>,
Bruce Axtens <bruce....@gmail.com> wrote:
There's a programming exercise on Exercism called two-fer. It takes an optional parameter. If the parameter is absent it returns "One for you, one for me."
If the parameter is present it is interpolated into the string in place of the "you".
As I understand it, and i'm no Forth programmer, optional items aren't a thing in
Forth. Rather, you either program for something or program for nothing. Thus, a two-fer word would expect a null-string or maybe even a null.
Am I understanding this right?It is impossible.
Any word can be executed in a nested situation, where there may be other items on the stack.
So there is no way in Forth to determine if one or two stack items are
passed to it.
There is ways around it, like a place holder that has a value NONE.
There's a programming exercise on Exercism called two-fer. It takes an optional parameter. If the parameter is absent it returns "One for you, one for me." If the parameter is present it is interpolated into the string in place of the "you".
There's a programming exercise on Exercism called two-fer. It takes an optional parameter. If the parameter is absent it returns "One for you, one for me." If the parameter is present it is interpolated into the string in place of the "you".
As I understand it, and i'm no Forth programmer, optional items aren't a thing in
Forth. Rather, you either program for something or program for nothing. Thus, a two-fer word would expect a null-string or maybe even a null.
Am I understanding this right?
Bruce.
There's a programming exercise on Exercism called two-fer. It takes an optional parameter. If the parameter is absent it returns "One for you, one for me." If the parameter is present it is interpolated into the string in place of the "you".
As I understand it, and i'm no Forth programmer, optional items aren't a thing in
Forth.
There's a programming exercise on Exercism called two-fer. It takes an optional parameter. If the parameter is absent it returns "One for you, one for me." If the parameter is present it is interpolated into the string in place of the "you".
As I understand it, and i'm no Forth programmer, optional items aren't a thing in
Forth. Rather, you either program for something or program for nothing. Thus, a two-fer word would expect a null-string or maybe even a null.
Ok, my above was for one or two parameters. So for just one optional parameter:^^^^^^^
"job" /go
: two-fer
." One for "
Depth if tell ii ." you" fi
Ok, my above was for one or two parameters. So for just one optional parameter:^^^^^^^
"job" /go
: two-fer
." One for "
Depth if tell ii ." you" fi
DEPTH is no solution. How can you tell the values present on the stack
were for your two-fer word? Perhaps they were left there for subsequent word?
Play by the rules; Rule, if parameter exists it for u:)
Play by the rules; Rule, if parameter exists it for u:)The problem is: not in the case when parameter may exist,
or there may be no parameter „for u”.
That was the initial assumption, correct?
There's a programming exercise on Exercism called two-fer. It takes an optional parameter. If the parameter is absent it returns "One for you, one for me." If the parameter is present it is interpolated into the string in place of the "you".
As I understand it, and i'm no Forth programmer, optional items aren't a thing in
Forth.
Ok, my above was for one or two parameters. So for just one optional parameter:^^^^^^^
"job" /go
: two-fer
." One for "
Depth if tell ii ." you" fi
DEPTH is no solution. How can you tell the values present on the stack
were for your two-fer word? Perhaps they were left there for subsequent word?
Another option is to invent a "syntax" for the problem and record the stack position and test if a parameter is present.
Another option is to invent a "syntax" for the problem and record the stack >> position and test if a parameter is present.
It could be made for example by adding always as a top parameter a value
that will confirm to each word like: „next 3 values are for you”. So the word
would firstly DUP and examine that „confirmation”, and if it means „the following n parameters are for you” — then „eat” them in usual way.
But of course it'd significantly slow the Forth machine down — so although it can be done, what's the sense? If anyone wants C/LISP/whatever — with their advantages, like ability to set „default parameters” — they're ready to be
embraced.
There's a programming exercise on Exercism called two-fer. It takes an optional parameter. If the parameter is absent it returns "One for you, one for me." If the parameter is present it is interpolated into the string in place of the "you".
As I understand it, and i'm no Forth programmer, optional items aren't a thing in
Forth. Rather, you either program for something or program for nothing. Thus, a two-fer word would expect a null-string or maybe even a null.
Am I understanding this right?
There's a programming exercise on Exercism called two-fer.
It takes an optional parameter. If the parameter is absent
it returns "One for you, one for me." If the parameter is present
it is interpolated into the string in place of the "you".
As I understand it, and i'm no Forth programmer, optional items aren't a thing
in Forth. Rather, you either program for something or program for nothing. Thus, a two-fer word would expect a null-string or maybe even a null.
Am I understanding this right?
On 20/11/2022 8:00 am, Zbig wrote:
Another option is to invent a "syntax" for the problem and record the stack
position and test if a parameter is present.
It could be made for example by adding always as a top parameter a value that will confirm to each word like: „next 3 values are for you”. So the word
would firstly DUP and examine that „confirmation”, and if it means „the
following n parameters are for you” — then „eat” them in usual way.
But of course it'd significantly slow the Forth machine down — so althoughAFAICS optional parameter is 'smoke and mirrors' in any language. It may
it can be done, what's the sense? If anyone wants C/LISP/whatever — with their advantages, like ability to set „default parameters” — they're ready to be
embraced.
be easier to fool users of an abstracted language such exists. Harder to
do in Forth because one is already at base level.
There's a programming exercise on Exercism called two-fer. It takes an optional parameter. If the parameter is absent it returns "One for you, one for me." If the parameter is present it is interpolated into the string in place of the "you".
As I understand it, and i'm no Forth programmer, optional items aren't a thing in
Forth. Rather, you either program for something or program for nothing. Thus, a two-fer word would expect a null-string or maybe even a null.
Am I understanding this right?
On Saturday, November 19, 2022 at 10:16:21 PM UTC-4, dxforth wrote:of the input string and be able to tell if it was empty or not.
On 20/11/2022 8:00 am, Zbig wrote:
AFAICS optional parameter is 'smoke and mirrors' in any language. It mayAnother option is to invent a "syntax" for the problem and record the stack
position and test if a parameter is present.
It could be made for example by adding always as a top parameter a value >>> that will confirm to each word like: „next 3 values are for you”. So the word
would firstly DUP and examine that „confirmation”, and if it means „the
following n parameters are for you” — then „eat” them in usual way. >>>
But of course it'd significantly slow the Forth machine down — so although
it can be done, what's the sense? If anyone wants C/LISP/whatever — with >>> their advantages, like ability to set „default parameters” — they're ready to be
embraced.
be easier to fool users of an abstracted language such exists. Harder to
do in Forth because one is already at base level.
I just realized that the "Forth" way of doing this would be similar to how values are implemented using "to". Rather than setting parameters on the stack, they would be on the command line after the word two-fer. Two-fer would then read the remainder
Did someone mention this idea already? I kinda skimmed a few posts.
On 24/11/2022 9:21 am, Lorem Ipsum wrote:of the input string and be able to tell if it was empty or not.
On Saturday, November 19, 2022 at 10:16:21 PM UTC-4, dxforth wrote:
On 20/11/2022 8:00 am, Zbig wrote:
AFAICS optional parameter is 'smoke and mirrors' in any language. It may >> be easier to fool users of an abstracted language such exists. Harder to >> do in Forth because one is already at base level.Another option is to invent a "syntax" for the problem and record the stack
position and test if a parameter is present.
It could be made for example by adding always as a top parameter a value >>> that will confirm to each word like: „next 3 values are for you”. So the word
would firstly DUP and examine that „confirmation”, and if it means „the
following n parameters are for you” — then „eat” them in usual way.
But of course it'd significantly slow the Forth machine down — so although
it can be done, what's the sense? If anyone wants C/LISP/whatever — with
their advantages, like ability to set „default parameters” — they're ready to be
embraced.
I just realized that the "Forth" way of doing this would be similar to how values are implemented using "to". Rather than setting parameters on the stack, they would be on the command line after the word two-fer. Two-fer would then read the remainder
Did someone mention this idea already? I kinda skimmed a few posts.Anton gave such an example, and sure, it has all the appearance of an optional parameter;
but ultimately one is testing a string and that's not optional. I had a look at several
C solutions on the website and AFAICT they just test a string too. IMO the 'two-fer'
exercise was poorly worded.
dxforth schrieb am Donnerstag, 24. November 2022 um 03:08:23 UTC+1:[...]
C does not have method or type polymorphism, even if one looks very long time.
The only multi-parameter words in Forth are N>R and SET-ORDER.
OTOH for amusement there are a number of words with multi-results like
?DUP or SEARCH-WORDLIST which cannot be processed by single words.
C does not have method or type polymorphism, even if one looks very long time.
The only multi-parameter words in Forth are N>R and SET-ORDER.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 52:17:19 |
Calls: | 6,712 |
Calls today: | 5 |
Files: | 12,243 |
Messages: | 5,355,177 |
Posted today: | 1 |