stack2.rig 898 B

12345678910111213141516171819202122232425262728293031
  1. -- Stack in RIGAL
  2. #STACK2
  3. -- stacks are modelled by lists.
  4. -- The only problem is removing elements from the end.
  5. -- "Base" RIGAL does not support this operation and you
  6. -- have either to store "current length" of the stack in a separate
  7. -- numeric variable, ( see "stack.rig") or
  8. -- make copy of the list (it is very expensive).
  9. -- However ther is a wayaround in the internals of Rigal
  10. -- descriptors:
  11. $ST:=(. 2 3 .);
  12. $ST1:=#POP($ST); -- changes $ST to (.2.) and returns it
  13. PRINT (.$ST $ST1.);
  14. -- There is, however, problem with "empty" stack, represented by NULL.
  15. -- The #POP operation cannot assign NULL to argument, so then NULL
  16. -- is only returned.
  17. $ST2:=#POP($ST1); -- leaves $ST1 as (.2.) and returns NULL
  18. PRINT (.$ST1 $ST2.);
  19. ##
  20. #POP $ST
  21. / IF #LIST($ST) AND (#LEN($ST)>1)->
  22. #CALL_PAS(91 $ST); RETURN $ST;
  23. ELSIF T->
  24. RETURN NULL
  25. FI;
  26. /
  27. ##