urbit/base/pub/doc/hoon/runes/wt/wtls.md
Anton Dyudin 6cbb6b060d Revert "remove docs for demo", "remove odds and ends", "demo network", "DEMO ONLY: root beak as %demo.", "DEMO ONLY: don't show doznec flapping.", "Prinrtf."
This reverts commit 8e1e40d75b3ab15c194b6bf9570f3edc46e2de58.
This reverts commit f073c490f9fd7c5abc033af4857df92229877de7.
This reverts commit f187d2d7e01a54823f3e979af9bbd148b398e7e9.
This reverts commit bc272862a73cfce1b118586ca39d3a377d841f1b.
This reverts commit 30a397513f8890a3406dc7ab91c6e067e3bbfbbb.
This reverts commit 4fc6856fb50d88c20a0f533392ca606641c5f38f.

Conflicts:
	urb/urbit.pill
	urb/zod/base/lib/drum.hoon
2015-06-15 18:10:02 -07:00

1.9 KiB

wutlus, ?+, %wtls

Switch with default

?+ is a synthetic rune that selects a case in q for the actual type of p with a default case, q. The labels in r must have the same icon as p The list of cases, r must be terminated by ==.

See also

wuthep, ?-, %wthp

Produces

Twig: [%wtls p=wing q=twig r=tine]

Sample

p is a ++wing. q is a twig. r is a ++tine.

Tall form

Kingside:

?+  p
  q
  p.i.r      q.i.r
  p.i.t.r    q.i.t.r
  p.i.t.t.r  q.i.t.t.r
==

Queenside:

?+    p
  q
    p.i.r      
  q.i.r
    p.i.t.r    
  q.i.t.r
    p.i.t.t.r  
  q.i.t.t.r
==

Wide form

?+(p p.i.r q.i.r, p.i.t.r q.i.t.r, p.i.t.t.r q.i.t.t.r)

Irregular form

None

Examples

~zod/try=> 
  =cor  |=  typ=@ta
        ?+  typ  0
        %a  1
        %b  2
        ==
new var %cor
~zod/try=> 
  (cor 'a')
1
~zod/try=> 
  (cor 'c')
0

Here is a simple example of ?+ showing that although the cases must match the icon of its input, all possible cases don't need to be covered since ?+ has a default case. We create a core, cor that takes an input typ, a @ta. Calling cor selects one of our cases when it is covered, or the default.

~zod/try=> 
  ?+  'a'  0
      %a  1
      ==
1
~zod/try=> 
  ?+  [0 'a']  0
      %a  1
      ==
! poke-mack-fail
! /~zod/try/~2014.11.2..16.45.31..7b2a:<[1 1].[3 7]>
! mint-vain
! ford: call ~hidper-sommur
! poking %poke-txt
! error in app %shell on ~zod at instance /shell/terminal
~zod/try=> 
  ?+  [0 1]  0
      [0 %a]  1
      ==
0

This example shows how ?- can fail. Our input icon must match the icon of our cases.