- WolfCode is a playful, wolf-themed programming language designed to teach basic programming concepts. It uses wolf pack terminology to represent various programming constructs.
- Bone: Represents integer values * Example: Howl my_bone as Bone
- Meat: Represents floating-point values * Example: Howl my_meat as Meat
- Biscuit: Represents boolean values (crunchy = true, soft = false) * Example: Howl my_biscuit as Biscuit
- Declaration: "Howl [name] as [type]" * Example: Howl age as Bone
- Assignment: "Mark [name] with [value]" * Example: Mark age with 5
- Addition: "Fetch [bone1] and [bone2]" * Example: Fetch age and 3
- Subtraction: "Chase [bone1] from [bone2]" * Example: Chase 2 from age
- Multiplication: "Bury [bone1] [bone2] times" * Example: Bury age 2 times
- Division: "Share [bone1] among [bone2] pack members" * Example: Share age among 2 pack members
- Comparison: "Sniff [bone1] and [bone2]" (returns Biscuit) * Example: Sniff age and 10
- If statement:
"If [condition] then
[action]
else
[other action]
Pack decides"
- While loop:
"While [condition] do
[actions]
Pack rests"
- For loop:
"For each [item] in [collection] do
[actions]
Pack moves on"
- Input: "Listen for [variable]" * Example: Listen for age
- Output: "Howl [message]" * Example: Howl "Your age is: " age
- The den is represented as an infinite series of caves
- Each cave stores one data item (Bone, Meat, or Biscuit)
- Navigate using: "Dig [direction] to [cave_name]" * Example: Dig north to age_cave
- Unconditional jump: "Run to [label]" * Example: Run to start_loop
- Conditional jump: "If [condition] then run to [label]" * Example: If Sniff age and 18 then run to adult_section
- Define function:
"Teach pack [function_name]
[function body]
Pack learned [function_name]"
- Call function: "Do [function_name]"
- Single line: "// [comment]"
- Multi-line: "/* [comment] */"
- Start: "Pack gathering"
- End: "Pack dispersing"
Pack gathering
Howl "Let's do some wolf math!"
Howl num1 as Bone
Howl num2 as Bone
Listen for num1
Listen for num2
Howl sum as Bone
Mark sum with Fetch num1 and num2
Howl "Sum: " sum
Howl diff as Bone
Mark diff with Chase num2 from num1
Howl "Difference: " diff
Howl product as Bone
Mark product with Bury num1 num2 times
Howl "Product: " product
Howl quotient as Meat
Mark quotient with Share num1 among num2 pack members
Howl "Quotient: " quotient
Pack dispersing
Pack gathering
Howl "Counting bones!"
Howl count as Bone
Mark count with 1
While Sniff count and 11 do
Howl "Bone count: " count
Mark count with Fetch count and 1
Pack rests
Howl "Even or Odd?"
For each num in count do
If Share num among 2 pack members then
Howl num " is even"
else
Howl num " is odd"
Pack decides
Pack moves on
Pack dispersing
Pack gathering
Teach pack calculate_dog_years
Listen for human_years
Howl dog_years as Bone
Mark dog_years with Bury human_years 7 times
Howl "In dog years, that's: " dog_years
Pack learned calculate_dog_years
Howl "Enter your age in human years:"
Do calculate_dog_years
Pack dispersing
Pack gathering
// Declare variables for each character
Howl h as Bone
Howl e as Bone
Howl l as Bone
Howl o as Bone
Howl space as Bone
Howl w as Bone
Howl r as Bone
Howl d as Bone
Howl exclamation as Bone
// Assign ASCII values
Mark h with 72 // ASCII for 'H'
Mark e with 101 // ASCII for 'e'
Mark l with 108 // ASCII for 'l'
Mark o with 111 // ASCII for 'o'
Mark space with 32 // ASCII for space
Mark w with 87 // ASCII for 'W'
Mark r with 114 // ASCII for 'r'
Mark d with 100 // ASCII for 'd'
Mark exclamation with 33 // ASCII for '!'
// Combine characters to form the message
Howl message as Bone
Mark message with Fetch h and e
Mark message with Fetch message and l
Mark message with Fetch message and l
Mark message with Fetch message and o
Mark message with Fetch message and space
Mark message with Fetch message and w
Mark message with Fetch message and o
Mark message with Fetch message and r
Mark message with Fetch message and l
Mark message with Fetch message and d
Mark message with Fetch message and exclamation
// Output the message
Howl message
Pack dispersing
- WolfCode๋ ๋๋ ๋ฌด๋ฆฌ์ ์ฉ์ด๋ฅผ ์ฌ์ฉํ์ฌ ํ๋ก๊ทธ๋๋ฐ ๊ตฌ์กฐ๋ฅผ ๋ํ๋ด๋ฉฐ, ๊ธฐ๋ณธ์ ์ธ ํ๋ก๊ทธ๋๋ฐ ๊ฐ๋ ์ ๊ฐ๋ฅด์น๋ ์ฌ๋ฏธ์๋ ์ธ์ด์ ๋๋ค.
- ๋ง๋ ์ด: cobaltbluestars(Renard), Raika the Wolfdog
- Bone: ์ ์ํ ๊ฐ
- ์: Howl my_bone as Bone
- Meat: ๋ถ๋ ์์์ ๊ฐ
- ์: Howl my_meat as Meat
- Biscuit: ๋ถ๋ฆฌ์ธ ๊ฐ (crunchy = ์ฐธ, soft = ๊ฑฐ์ง)
- ์: Howl my_biscuit as Biscuit
- ๋ณ์ ์ ์ธ: Howl [์ด๋ฆ] as [ํ์ ]
- ์: Howl age as Bone
- ๊ฐ ํ ๋น: Mark [์ด๋ฆ] with [๊ฐ]
- ์: Mark age with 5
- ๋ง์ : Fetch [bone1] and [bone2]
- ์: Fetch age and 3
- ๋บ์ : Chase [bone1] from [bone2]
- ์: Chase 2 from age
- ๊ณฑ์ : Bury [bone1] [bone2] times
- ์: Bury age 2 times
- ๋๋์ : Share [bone1] among [bone2] pack members
- ์: Share age among 2 pack members
- ๋น๊ต: Sniff [bone1] and [bone2] (Biscuit์ ๋ฐํ)
- ์: Sniff age and 10
- If ์กฐ๊ฑด๋ฌธ:
If [์กฐ๊ฑด] then
[ํ๋]
else
[๋ค๋ฅธ ํ๋]
Pack decides
-While ๋ฐ๋ณต๋ฌธ:
While [์กฐ๊ฑด] do
[ํ๋]
Pack rests
- For ๋ฐ๋ณต๋ฌธ:
For each [ํญ๋ชฉ] in [์ปฌ๋ ์
] do
[ํ๋]
Pack moves on
- ์ ๋ ฅ ๋ฐ๊ธฐ: Listen for [๋ณ์]
- ์: Listen for age
- ์ถ๋ ฅํ๊ธฐ: Howl [๋ฉ์์ง]
- ์: Howl "Your age is: " age
-
Den์ ๋ฌดํํ "caves"๋ก ํํ๋จ
-
๊ฐ cave๋ ํ๋์ ๋ฐ์ดํฐ ํญ๋ชฉ(Bone, Meat, ๋๋ Biscuit)์ ์ ์ฅ
-
ํ์: Dig [๋ฐฉํฅ] to [cave_name]
- ์: Dig north to age_cave
- ๋ฌด์กฐ๊ฑด ์ ํ: Run to [label]
- ์: Run to start_loop
- ์กฐ๊ฑด๋ถ ์ ํ: If [์กฐ๊ฑด] then run to [label]
- ์: If Sniff age and 18 then run to adult_section
- ํจ์ ์ ์:
Teach pack [ํจ์๋ช
]
[ํจ์ ๋ด์ฉ]
Pack learned [ํจ์๋ช
]
- ํจ์ ํธ์ถ: Do [ํจ์๋ช ]
- ๋จ์ผ ์ค ์ฃผ์: // [์ฃผ์ ๋ด์ฉ]
- ์ฌ๋ฌ ์ค ์ฃผ์: /* [์ฃผ์ ๋ด์ฉ] */
- ์์: Pack gathering
- ๋: Pack dispersing
Pack gathering
// ๋๋ ๋ฌด๋ฆฌ ์ ์ธ
Howl wolf_pack as Den
Mark wolf_pack with [{"name": "leo", "age": 5}, {"name": "jax", "age": 3}, {"name": "matt", "age": 2}, {"name": "renard", "age": 1}]
// ํต ์ ๋ ฌ ํจ์ ์ ์
Teach pack quick_sort
Listen for wolves
// ๋ฆฌ์คํธ๊ฐ 1 ์ดํ์ธ ๊ฒฝ์ฐ ๊ทธ๋๋ก ๋ฐํ
If Sniff length of wolves and 1 then
Howl sorted_wolves as Den
Mark sorted_wolves with wolves
Pack learned quick_sort
Pack decides
// ํผ๋ฒ ์ ํ: ์ฒซ ๋ฒ์งธ ๋๋๋ฅผ ํผ๋ฒ์ผ๋ก ์ฌ์ฉ
Howl pivot as Den
Mark pivot with wolves[0]
// ํผ๋ฒ์ ๊ธฐ์ค์ผ๋ก ๋๋๊ธฐ
Howl less as Den
Howl greater as Den
For each wolf in wolves do
If Sniff wolf.age and pivot.age then
Howl "๋์ด ์ ์: " wolf.name
Mark less with Fetch less and wolf
else
Howl "๋์ด ๋ง์ ๋๋ ๊ฐ์: " wolf.name
Mark greater with Fetch greater and wolf
Pack decides
Pack moves on
// ์ฌ๊ท์ ์ผ๋ก ์ ๋ ฌ ๋ฐ ํฉ์น๊ธฐ
Howl sorted_less as Den
Howl sorted_greater as Den
Mark sorted_less with Do quick_sort(less)
Mark sorted_greater with Do quick_sort(greater)
Howl sorted_wolves as Den
Mark sorted_wolves with Fetch sorted_less and [pivot] and sorted_greater
Howl "์ ๋ ฌ๋ ๋๋ ๋ฌด๋ฆฌ: " sorted_wolves
Pack learned quick_sort
// ์ ๋ ฌ ์คํ
Howl sorted_pack as Den
Mark sorted_pack with Do quick_sort(wolf_pack)
Howl "์ต์ข
์ ๋ ฌ ๊ฒฐ๊ณผ: " sorted_pack
Pack dispersing