September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -0,0 +1,20 @@
/**
<doc><h2>Hash from two arrays, in Neko</h2></doc>
**/
var sprintf = $loader.loadprim("std@sprintf", 2)
var array_keys = $array("one",2,"three",4,"five")
var array_vals = $array("six",7,"eight",9,"zero")
var elements = $asize(array_keys)
var table = $hnew(elements)
var step = elements
while (step -= 1) >= 0 $hadd(table, $hkey(array_keys[step]), array_vals[step])
/*
$hiter accepts a hashtable and a function that accepts two args, key, val
*/
var show = function(k, v) $print("Hashed key: ", sprintf("%10d", k), " Value: ", v, "\n")
$hiter(table, show)

View file

@ -2,6 +2,4 @@ let keys = [| "foo"; "bar"; "baz" |]
and vals = [| 16384; 32768; 65536 |]
and hash = Hashtbl.create 0;;
for i = 0 to Array.length keys - 1 do
Hashtbl.add hash keys.(i) vals.(i)
done;;
Array.iter2 (Hashtbl.add hash) keys vals;;

View file

@ -1,18 +1,24 @@
/*REXX program demonstrates hashing of a stemmed array (from a key). */
/*names of the 9 regular polygons*/
values='triangle quadrilateral pentagon hexagon heptagon octagon nonagon decagon dodecagon'
keys ='thuhree vour phive sicks zeaven ate nein den duzun'
/* [↑] superfluous blanks added to humorous */
/* keys just because it looks prettier. */
call hash values,keys /*hash the keys to the values. */
parse arg query . /*get what was specified on C.L. */
if query=='' then exit /*Nothing? Then leave Dodge City*/
pad=left('',30) /*used for padding the display. */
say 'key:' query pad "value:" hash.query /*show some stuff.*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────HASH subroutine─────────────────────*/
hash: procedure expose hash.; parse arg v,k,hash.
do j=1 until map==''; map=word(k,j)
hash.map=word(v,j)
end /*j*/
return
/*REXX program demonstrates hashing of a stemmed array (from a key or multiple keys)*/
key.= /*names of the nine regular polygons. */
vals= 'triangle quadrilateral pentagon hexagon heptagon octagon nonagon decagon dodecagon'
key.1='thuhree vour phive sicks zeaven ate nein den duzun'
key.2='three four five six seven eight nine ten twelve'
key.3='3 4 5 6 7 8 9 10 12'
key.4='III IV V VI VII VIII IX X XII'
key.5='iii iv v vi vii viii ix x xii'
hash.='(not defined)' /* [↑] blanks added to humorous keys */
/* just because it looks prettier.*/
do k=1 while key.k\==''
call hash vals,key.k /*hash the keys to the values. */
end /*k*/
parse arg query . /*obtain what was specified on the C.L.*/
if query=='' then exit /*Nothing? Then leave Dodge City. */
say 'key:' left(query,40) "value:" hash.query /*display some stuff to the terminal. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
hash: parse arg @val,@key
do j=1 for words(@key); map= word(@key, j)
hash.map= word(@val, j)
end /*j*/
return