Names to numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|Quackery}}: small tweak)
Line 1,929: Line 1,929:
=={{header|Quackery}}==
=={{header|Quackery}}==


The idea is that, with a few tweaks, a string such as <pre>one billion, two hundred and thirty four million, five hundred and sixty seven thousand, eight hundred and ninety</pre> can ''be'' a valid Quackery program.
The idea is that, with a few tweaks and appropriate definitions for number names etc, a string such as <pre>one billion, two hundred and thirty four million, five hundred and sixty seven thousand, eight hundred and ninety</pre> can ''be'' a valid Quackery program.


The tweaks turn it into <pre>[ {{ , one billion , two hundred thirty four million , five hundred sixty seven thousand , eight hundred ninety }} ]</pre> by prepending <code>{{ ,</code>, inserting a space in front of each comma, and appending <code>}}</code> before being compiled with <code>build</code>, and removing references to the word <code>and</code> after compilation.
The tweaks turn it into the nest <pre>[ {{ one billion , two hundred thirty four million , five hundred sixty seven thousand , eight hundred ninety }} ]</pre> by prepending <code>{{ </code>, inserting a space in front of each comma, and appending <code> }}</code> before being compiled with <code>build</code>, and removing references to the word <code>and</code> after compilation.




Finally, the compiled nest is executed with <code>do</code>.
Finally, the compiled nest is executed with <code>do</code>.


<lang Quackery>
<lang Quackery> [ 1 + ] is one ( --> n )
[ 1 + ] is one ( --> n )
[ 2 + ] is two ( --> n )
[ 2 + ] is two ( --> n )
[ 3 + ] is three ( --> n )
[ 3 + ] is three ( --> n )
Line 1,972: Line 1,971:
[ 0 ] is , ( --> n )
[ 0 ] is , ( --> n )


[ this ] is {{ ( --> [ )
[ this , ] is {{ ( --> [ )


[ over {{ = iff
[ over ' {{ = iff
nip done
nip done
+ again ] is }} ( [ * --> n )
+ again ] is }} ( [ * --> n )


[ $ "{{ , " swap
[ $ "{{ " swap
witheach
witheach
[ dup char , = if
[ dup char , = if
Line 1,988: Line 1,987:
swap witheach
swap witheach
[ dup ' and = iff
[ dup ' and = iff
drop
drop
else
else
[ nested join ] ]
[ nested join ] ]
do ] is name->number ( $ --> n )
do ] is name->number ( $ --> n )