Transcript show: 'Derp'.
printSomething: 'Derpy'.
"The method above produced this error:"
"prog.st:3: expected expression"
printSomething: what
10 timesRepeat: [
Transcript show:what.
Transcript cr.
].
I'm trying to teach myself Smalltalk now, and I still haven't figured out how to call a function that I've written. I tried to call the function printSomething
with the parameter 'Derpy'
using the statement printSomething: 'Derpy'.
, but instead of calling the function, it produced the following error: prog.st:3: expected expression
.
What am I doing wrong here, and what is the correct way to call functions with parameters in Smalltalk? None of the tutorials that I've read have answered my question so far, and I'm still a bit confused.
I suspect that your errors are twofold:
Object class: #Example [
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Smalltalk Examples'
]
Example class extend [
printSomething: what
10 timesRepeat: [
Transcript show:what.
]
]
Eval [
Transcript show: 'Derp'.
(Example new) printSomething: 'Derpy'.
]
Note the Eval []
block, and that you create an instance of Example
, not NameOfSubclass
.