Posted to tcl by Stu at Thu May 16 14:08:39 GMT 2024view raw

  1. $ cat ptycl_example1.ptycl
  2.  
  3. //
  4. // pTycl example
  5. //
  6. // Basics
  7. //
  8.  
  9. class Clown () {
  10.  
  11. def __init__ (self, name) {
  12. self._name = name
  13. self._eman = ""
  14. for c in self._name {
  15. if len(self._eman) == len(self._name) - 1 {
  16. c = c.upper()
  17. } else {
  18. c = c.lower()
  19. }
  20. self._eman = c + self._eman
  21. }
  22. }
  23.  
  24. def juggle ($, nballs) {
  25. print(f"{$name()} is juggling {nballs} balls")
  26. }
  27.  
  28. def intro ($) {
  29. print(f"{$_name} is my name, or {$_eman} in the mirror world")
  30. }
  31.  
  32. mef name () {
  33. return $_name
  34. }
  35.  
  36. mef dance (speed) {
  37. if speed < 3 {
  38. dance = "slow"
  39. } elif speed == 5 {
  40. dance = "medium"
  41. } elif speed > 11 {
  42. dance = "fast"
  43. } else {
  44. dance = "regular"
  45. }
  46. print(f"{$_name} is {dance} dancing")
  47. }
  48.  
  49. mef sing (volume) {
  50. print(f"{$name()} is singing at a {volume} volume")
  51. }
  52.  
  53. mef exclaim (what) {
  54. print(f"{$name()} exclaims {what}!")
  55. }
  56.  
  57. mef bye () {
  58. print(f"{$name()} says goodbye, until next time")
  59. }
  60.  
  61. } # class Clown
  62.  
  63. def main () {
  64. name = "Bingo"
  65. c = Clown(name)
  66. if c.name() != name {
  67. print("Unpossible?")
  68. exit()
  69. }
  70. c.intro()
  71. c.sing('soft')
  72. for i in (1,5,6,14) {
  73. c.dance(i)
  74. if i == 5 {
  75. c.sing('whisper')
  76. }
  77. }
  78. c.sing('gleeful')
  79. // Should probably be "for i in range() ..."
  80. i = 4
  81. while (i := i - 1) > -1 {
  82. c.juggle(i)
  83. if i == 0 {
  84. c.exclaim('Oops')
  85. }
  86. }
  87. c.sing('soft')
  88. c.bye()
  89. }
  90.  
  91.  
  92. if __name__ == "__main__" {
  93. main()
  94. }
  95.  
  96.  
  97. // EOF
  98.  
  99.  
  100.  
  101.  
  102.  
  103. $ ptycl < ptycl_example1.ptycl
  104.  
  105. class Clown ():
  106.  
  107. def __init__ (self, name):
  108. self._name = name
  109. self._eman = ""
  110. for c in self._name:
  111. if len(self._eman) == len(self._name) - 1:
  112. c = c.upper()
  113. else:
  114. c = c.lower()
  115. self._eman = c + self._eman
  116.  
  117. def juggle (self, nballs):
  118. print(f"{self.name()} is juggling {nballs} balls")
  119.  
  120. def intro (self):
  121. print(f"{self._name} is my name, or {self._eman} in the mirror world")
  122.  
  123. def name (self):
  124. return self._name
  125.  
  126. def dance (self, speed):
  127. if speed < 3:
  128. dance = "slow"
  129. elif speed == 5:
  130. dance = "medium"
  131. elif speed > 11:
  132. dance = "fast"
  133. else: dance = "regular"
  134. print(f"{self._name} is {dance} dancing")
  135.  
  136. def sing (self, volume):
  137. print(f"{self.name()} is singing at a {volume} volume")
  138.  
  139. def exclaim (self, what):
  140. print(f"{self.name()} exclaims {what}!")
  141.  
  142. def bye (self):
  143. print(f"{self.name()} says goodbye, until next time")
  144.  
  145.  
  146.  
  147. def main ():
  148. name = "Bingo"
  149. c = Clown(name)
  150. if c.name() != name:
  151. print("Unpossible?")
  152. exit()
  153. c.intro()
  154. c.sing('soft')
  155. for i in (1,5,6,14):
  156. c.dance(i)
  157. if i == 5:
  158. c.sing('whisper')
  159. c.sing('gleeful')
  160. i = 4
  161. while (i := i - 1) > -1:
  162. c.juggle(i)
  163. if i == 0:
  164. c.exclaim('Oops')
  165. c.sing('soft')
  166. c.bye()
  167.  
  168.  
  169. if __name__ == "__main__":
  170. main()
  171.  
  172.  
  173.  
  174.  
  175.  
  176. $ ptycl.py < ptycl_example1.ptycl | python
  177.  
  178. Bingo is my name, or Ognib in the mirror world
  179. Bingo is singing at a soft volume
  180. Bingo is slow dancing
  181. Bingo is medium dancing
  182. Bingo is singing at a whisper volume
  183. Bingo is regular dancing
  184. Bingo is fast dancing
  185. Bingo is singing at a gleeful volume
  186. Bingo is juggling 3 balls
  187. Bingo is juggling 2 balls
  188. Bingo is juggling 1 balls
  189. Bingo is juggling 0 balls
  190. Bingo exclaims Oops!
  191. Bingo is singing at a soft volume
  192. Bingo says goodbye, until next time
  193.