YAPC::EU 2018 Glasgow Update!

This commit is contained in:
Ingy döt Net 2018-08-17 15:15:24 +01:00
parent 22f33d4004
commit 4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions

View file

@ -2,46 +2,45 @@ import system'routines.
import extensions.
import extensions'routines.
joinable = (:aFormer:aLater)(aFormer[aFormer length - 1] == aLater[0]).
joinable(former,later) = (former[former length - 1] == later[0]).
dispatcher =
{
eval(object anArray, Func2 aFunction)
eval(object a, Func2 f)
[
^ aFunction(anArray[0],anArray[1]).
^ f(a[0],a[1]).
]
eval(object anArray, Func3 aFunction)
eval(object a, Func3 f)
[
^ aFunction(anArray[0], anArray[1],anArray[2]).
^ f(a[0], a[1],a[2]).
]
eval(object anArray, Func4 aFunction)
eval(object a, Func4 f)
[
^ aFunction(anArray[0],anArray[1],anArray[2],anArray[3]).
^ f(a[0],a[1],a[2],a[3]).
]
eval(object anArray, Func5 aFunction)
eval(object a, Func5 f)
[
^ aFunction(anArray[0],anArray[1],anArray[2],anArray[3],anArray[4]).
^ f(a[0],a[1],a[2],a[3],a[4]).
]
}.
class AmbValueCollection
{
object theCombinator.
constructor new(V<object> Arguments)
generic constructor new(V<object> args)
[
theCombinator := SequentialEnumerator new(Arguments).
theCombinator := SequentialEnumerator new(args).
]
seek : aCondition
seek : cond
[
theCombinator reset.
theCombinator seekEach(:v)(dispatcher eval(v,aCondition))
theCombinator seekEach(:v)(dispatcher eval(v,cond))
]
do : aFunction
@ -55,11 +54,11 @@ class AmbValueCollection
ambOperator =
{
generic for(V<object> Arguments)
= AmbValueCollection new(Arguments).
generic for(V<object> args)
= AmbValueCollection new(args).
}.
public program =
public program
[
try(ambOperator
for(("the","that","a"),("frog", "elephant", "thing"),("walked", "treaded", "grows"),("slowly", "quickly"));
@ -72,5 +71,5 @@ public program =
]
}.
console readChar.
].
console readChar
]

View file

@ -1,22 +1,22 @@
/*REXX program demonstrates the Amd operator, choosing a word from each set. */
@.=; @.1 = "the that a"
@.2 = "frog elephant thing"
@.3 = "walked treaded grows"
@.=; @.1 = "the that a"
@.2 = "frog elephant thing"
@.3 = "walked treaded grows"
@.4 = "slowly quickly"
call Amb 1 /*find all word combinations that works*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Amb: procedure expose @.; parse arg # x; arg . u /*2nd parse uppercases U*/
do j=1 until @.j==''; end /*locate a null string. */
t=j-1 /*define number of sets.*/
if #>t then do; w=word(u,1) /*W: is a uppercased U*/
do n=2 to words(u); ?=word(u, n)
if left(?, 1) \== right(w, 1) then return; w=?
end /*n*/
say space(x)
Amb: procedure expose @.; parse arg # x; arg . u /*ARG uppercases U values. */
do j=1 until @.j=='' /*locate a null string. */
end /*j*/
t= j-1 /*define number of sets. */
if #>t then do; y=word(u, 1) /*Y: is a uppercased U. */
do n=2 to words(u); ?=word(u, n)
if left(?, 1) \== right(y, 1) then return; y=?
end /*n*/
say space(x) /*¬show superfluous blanks.*/
end
do k=1 for words(@.#) /*process words in sets.*/
call Amb #+1 x word(@.#, k) /*generate combinations,*/
end /*k*/ /* [↑] (recursively).*/
return
do k=1 for words(@.#); call Amb #+1 x word(@.#, k)
end /*k*/ /* [↑] generate all combs */
return /* recursively. */

32
Task/Amb/Ring/amb.ring Normal file
View file

@ -0,0 +1,32 @@
# Project : Amb
set1 = ["the","that","a"]
set2 = ["frog","elephant","thing"]
set3 = ["walked","treaded","grows"]
set4 = ["slowly","quickly"]
text = amb(set1,set2,set3,set4)
if text != ""
see "Correct sentence would be: " + nl + text + nl
else
see "Failed to fine a correct sentence."
ok
func wordsok(string1, string2)
if substr(string1,len(string1),1) = substr(string2,1,1)
return true
ok
return false
func amb(a,b,c,d)
for a2 = 1 to len(a)
for b2 =1 to len(b)
for c2 = 1 to len(c)
for d2 = 1 to len(d)
if wordsok(a[a2],b[b2]) and wordsok(b[b2],c[c2]) and wordsok(c[c2],d[d2])
return a[a2]+" "+b[b2]+" "+c[c2]+" "+d[d2]
ok
next
next
next
next
return ""