Posted to tcl by Stu at Thu May 16 14:08:39 GMT 2024view raw
- $ cat ptycl_example1.ptycl
- //
- // pTycl example
- //
- // Basics
- //
- class Clown () {
- def __init__ (self, name) {
- self._name = name
- self._eman = ""
- for c in self._name {
- if len(self._eman) == len(self._name) - 1 {
- c = c.upper()
- } else {
- c = c.lower()
- }
- self._eman = c + self._eman
- }
- }
- def juggle ($, nballs) {
- print(f"{$name()} is juggling {nballs} balls")
- }
- def intro ($) {
- print(f"{$_name} is my name, or {$_eman} in the mirror world")
- }
- mef name () {
- return $_name
- }
- mef dance (speed) {
- if speed < 3 {
- dance = "slow"
- } elif speed == 5 {
- dance = "medium"
- } elif speed > 11 {
- dance = "fast"
- } else {
- dance = "regular"
- }
- print(f"{$_name} is {dance} dancing")
- }
- mef sing (volume) {
- print(f"{$name()} is singing at a {volume} volume")
- }
- mef exclaim (what) {
- print(f"{$name()} exclaims {what}!")
- }
- mef bye () {
- print(f"{$name()} says goodbye, until next time")
- }
- } # class Clown
- def main () {
- name = "Bingo"
- c = Clown(name)
- if c.name() != name {
- print("Unpossible?")
- exit()
- }
- c.intro()
- c.sing('soft')
- for i in (1,5,6,14) {
- c.dance(i)
- if i == 5 {
- c.sing('whisper')
- }
- }
- c.sing('gleeful')
- // Should probably be "for i in range() ..."
- i = 4
- while (i := i - 1) > -1 {
- c.juggle(i)
- if i == 0 {
- c.exclaim('Oops')
- }
- }
- c.sing('soft')
- c.bye()
- }
- if __name__ == "__main__" {
- main()
- }
- // EOF
- $ ptycl < ptycl_example1.ptycl
- class Clown ():
- def __init__ (self, name):
- self._name = name
- self._eman = ""
- for c in self._name:
- if len(self._eman) == len(self._name) - 1:
- c = c.upper()
- else:
- c = c.lower()
- self._eman = c + self._eman
- def juggle (self, nballs):
- print(f"{self.name()} is juggling {nballs} balls")
- def intro (self):
- print(f"{self._name} is my name, or {self._eman} in the mirror world")
- def name (self):
- return self._name
- def dance (self, speed):
- if speed < 3:
- dance = "slow"
- elif speed == 5:
- dance = "medium"
- elif speed > 11:
- dance = "fast"
- else: dance = "regular"
- print(f"{self._name} is {dance} dancing")
- def sing (self, volume):
- print(f"{self.name()} is singing at a {volume} volume")
- def exclaim (self, what):
- print(f"{self.name()} exclaims {what}!")
- def bye (self):
- print(f"{self.name()} says goodbye, until next time")
- def main ():
- name = "Bingo"
- c = Clown(name)
- if c.name() != name:
- print("Unpossible?")
- exit()
- c.intro()
- c.sing('soft')
- for i in (1,5,6,14):
- c.dance(i)
- if i == 5:
- c.sing('whisper')
- c.sing('gleeful')
- i = 4
- while (i := i - 1) > -1:
- c.juggle(i)
- if i == 0:
- c.exclaim('Oops')
- c.sing('soft')
- c.bye()
- if __name__ == "__main__":
- main()
- $ ptycl.py < ptycl_example1.ptycl | python
- Bingo is my name, or Ognib in the mirror world
- Bingo is singing at a soft volume
- Bingo is slow dancing
- Bingo is medium dancing
- Bingo is singing at a whisper volume
- Bingo is regular dancing
- Bingo is fast dancing
- Bingo is singing at a gleeful volume
- Bingo is juggling 3 balls
- Bingo is juggling 2 balls
- Bingo is juggling 1 balls
- Bingo is juggling 0 balls
- Bingo exclaims Oops!
- Bingo is singing at a soft volume
- Bingo says goodbye, until next time