2
0

TrySmalltalk.st 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. Widget subclass: #TrySmalltalkWidget
  2. instanceVariableNames: 'workspace contents header'
  3. category: 'TrySmalltalk'!
  4. !TrySmalltalkWidget methodsFor: 'accessing'!
  5. workspace
  6. ^ workspace ifNil: [
  7. workspace := SourceArea new]
  8. !
  9. contents: aString
  10. self workspace val: aString
  11. !
  12. contents
  13. ^self workspace val
  14. !
  15. setTitle: aString
  16. header contents: [:html | html with: aString]
  17. ! !
  18. !TrySmalltalkWidget methodsFor: 'rendering'!
  19. renderOn: html
  20. html div
  21. class: 'profStef';
  22. with: [header := html h2];
  23. with: [self workspace renderOn: html];
  24. with: [self renderButtonsOn: html].
  25. ProfStef default
  26. widget: self;
  27. showCurrentLesson
  28. !
  29. renderButtonsOn: html
  30. html button
  31. with: 'DoIt';
  32. title: 'ctrl+d';
  33. onClick: [self workspace doIt].
  34. html button
  35. with: 'PrintIt';
  36. title: 'ctrl+p';
  37. onClick: [self workspace printIt].
  38. html button
  39. with: 'InspectIt';
  40. title: 'ctrl+i';
  41. onClick: [self workspace inspectIt]
  42. ! !
  43. Object subclass: #AbstractTutorial
  44. instanceVariableNames: ''
  45. category: 'TrySmalltalk'!
  46. !AbstractTutorial commentStamp!
  47. Parent class of all ProfStef tutorials.
  48. To create your own tutorial:
  49. - subclass AbstractTutorial
  50. - implement a few methods which returns a Lesson instance
  51. - implement tutorial which returns a Collection of selectors to the methods you've created.!
  52. !AbstractTutorial methodsFor: 'accessing'!
  53. indexOfLesson: aSelector
  54. ^self tableOfContents indexOf: aSelector.
  55. !
  56. tableOfContents
  57. ^ #(
  58. 'welcome'
  59. 'testLesson'
  60. 'theEnd'
  61. )
  62. !
  63. lessonAt: anInteger
  64. | lessonSelector |
  65. lessonSelector := self tableOfContents at: anInteger.
  66. ^ self perform: lessonSelector.
  67. !
  68. size
  69. ^ self tableOfContents size
  70. ! !
  71. !AbstractTutorial methodsFor: 'pages'!
  72. welcome
  73. ^ Lesson
  74. title: 'Welcome'
  75. contents: '"Hi, this is a test tutorial."'
  76. !
  77. testLesson
  78. ^ Lesson
  79. title: 'Test Lesson'
  80. contents: '"This lesson is a test"'
  81. !
  82. theEnd
  83. ^ Lesson
  84. title: 'The End'
  85. contents: '"And that''d be pretty much it :)"'
  86. ! !
  87. Object subclass: #Lesson
  88. instanceVariableNames: 'title contents'
  89. category: 'TrySmalltalk'!
  90. !Lesson methodsFor: 'accessing'!
  91. contents
  92. ^ contents ifNil: [contents := '']
  93. !
  94. contents: aString
  95. contents := aString
  96. !
  97. title: aString
  98. title := aString
  99. !
  100. title
  101. ^ title ifNil: [title := '']
  102. ! !
  103. !Lesson class methodsFor: 'instance creation'!
  104. title: aTitle contents: someContents
  105. ^ (self new)
  106. title: aTitle;
  107. contents: someContents
  108. ! !
  109. Object subclass: #TutorialPlayer
  110. instanceVariableNames: 'tutorialPosition tutorial'
  111. category: 'TrySmalltalk'!
  112. !TutorialPlayer commentStamp!
  113. I can navigate through an AbstractTutorial subclass. With #next and #previous you can go forward and backward through the tutorial.!
  114. !TutorialPlayer methodsFor: 'accessing'!
  115. currentLesson
  116. ^ self tutorial lessonAt: self tutorialPosition.
  117. !
  118. size
  119. ^ self tutorial size
  120. !
  121. tutorial
  122. ^ tutorial ifNil: [tutorial := SmalltalkSyntaxTutorial new]
  123. !
  124. tutorial: aTutorial
  125. tutorial := aTutorial
  126. !
  127. tutorialPosition
  128. ^ tutorialPosition ifNil: [
  129. self rewind.
  130. tutorialPosition.
  131. ].
  132. !
  133. tutorialPosition: aTutorialPosition
  134. tutorialPosition := aTutorialPosition
  135. ! !
  136. !TutorialPlayer methodsFor: 'navigation'!
  137. first
  138. self rewind.
  139. ^ self currentLesson
  140. !
  141. last
  142. tutorialPosition := self size.
  143. ^ self currentLesson
  144. !
  145. next
  146. self tutorialPosition < self size
  147. ifTrue: [tutorialPosition := tutorialPosition + 1].
  148. ^ self currentLesson
  149. !
  150. previous
  151. tutorialPosition > 1 ifTrue: [tutorialPosition := tutorialPosition - 1].
  152. ^ self currentLesson
  153. !
  154. rewind
  155. tutorialPosition := 1.
  156. ! !
  157. Object subclass: #ProfStef
  158. instanceVariableNames: 'tutorialPlayer widget'
  159. category: 'TrySmalltalk'!
  160. !ProfStef commentStamp!
  161. A ProfStef is the Smalltalk teacher. To start the tutorial, evaluate:
  162. ProfStef go.
  163. To go to the next lesson evaluate:
  164. ProfStef next.
  165. To execute your own tutorial:
  166. ProfStef goOn: MyOwnTutorial
  167. To see a table of contents with all defined tutorials:
  168. ProfStef contents!
  169. !ProfStef methodsFor: 'accessing'!
  170. tutorialPlayer
  171. ^ tutorialPlayer ifNil: [tutorialPlayer := TutorialPlayer new]
  172. !
  173. progress
  174. ^ '(', self tutorialPositionString, '/', self tutorialSizeString, ')'.
  175. !
  176. tutorialPositionString
  177. ^ self tutorialPlayer tutorialPosition asString.
  178. !
  179. tutorialSizeString
  180. ^ self tutorialPlayer size asString
  181. !
  182. widget: aWidget
  183. widget := aWidget
  184. !
  185. showCurrentLesson
  186. | lesson |
  187. lesson := self tutorialPlayer currentLesson.
  188. widget contents: lesson contents.
  189. widget setTitle: lesson title , ' ' , self progress.
  190. ! !
  191. !ProfStef methodsFor: 'navigation'!
  192. first
  193. self tutorialPlayer first.
  194. ^ self showCurrentLesson.
  195. !
  196. next
  197. self tutorialPlayer next.
  198. ^ self showCurrentLesson.
  199. !
  200. previous
  201. self tutorialPlayer previous.
  202. ^ self showCurrentLesson.
  203. ! !
  204. ProfStef class instanceVariableNames: 'instance'!
  205. !ProfStef class methodsFor: 'initialize'!
  206. default
  207. ^ instance ifNil: [instance := self new]
  208. ! !
  209. !ProfStef class methodsFor: 'navigation'!
  210. first
  211. ^ self default first.
  212. !
  213. previous
  214. ^ self default previous.
  215. !
  216. next
  217. ^ self default next.
  218. !
  219. go
  220. self first.
  221. ! !
  222. AbstractTutorial subclass: #SmalltalkSyntaxTutorial
  223. instanceVariableNames: ''
  224. category: 'TrySmalltalk'!
  225. !SmalltalkSyntaxTutorial commentStamp!
  226. The default ProfStef tutorial to learn Smalltalk syntax!
  227. !SmalltalkSyntaxTutorial methodsFor: 'contents'!
  228. tableOfContents
  229. ^ #( 'welcome'
  230. 'doingVSPrinting'
  231. 'printing'
  232. 'basicTypesNumbers'
  233. "'basicTypesCharacters'"
  234. 'basicTypesString'
  235. "'basicTypesSymbol'"
  236. 'basicTypesArray'
  237. 'basicTypesDynamicArray'
  238. 'messageSyntaxUnary'
  239. 'messageSyntaxBinary'
  240. 'messageSyntaxKeyword'
  241. 'messageSyntaxExecutionOrder'
  242. 'messageSyntaxExecutionOrderParentheses'
  243. 'mathematicalPrecedence'
  244. 'messageSyntaxCascade'
  245. 'messageSyntaxCascadeShouldNotBeHere'
  246. 'blocks'
  247. 'blocksAssignation'
  248. 'conditionals'
  249. 'loops'
  250. 'iterators'
  251. 'instanciation'
  252. 'reflection'
  253. 'reflectionContinued'
  254. "'pharoEnvironment'"
  255. "'debugger'"
  256. 'theEnd' )
  257. ! !
  258. !SmalltalkSyntaxTutorial methodsFor: 'pages'!
  259. basicTypesArray
  260. ^ Lesson
  261. title: 'Basic types: Array'
  262. contents:
  263. '"Literal arrays are created at parse time:"
  264. #(1 2 3).
  265. #( 1 2 3 #(4 5 6)) size.
  266. #(1 2 4) isEmpty.
  267. #(1 2 3) first.
  268. #(''hello'' ''Javascript'') at: 2 put: ''Smalltalk''; yourself.
  269. ProfStef next.'
  270. !
  271. basicTypesCharacters
  272. ^ Lesson
  273. title: 'Basic types: Characters'
  274. contents:
  275. '"A Character can be instantiated using $ operator:"
  276. $A.
  277. $A class.
  278. $B charCode.
  279. Character cr.
  280. Character space.
  281. "You can print all 256 characters of the ASCII extended set:"
  282. Character allByteCharacters.
  283. ProfStef next.'
  284. !
  285. basicTypesDynamicArray
  286. ^ Lesson
  287. title: 'Basic types: Dynamic Array'
  288. contents:
  289. '"Dynamic Arrays are created at execution time:"
  290. { (2+3) . (6*6) }.
  291. { (2+3) . (6*6) . ''hello'', '' Stef''} size.
  292. { ProfStef } first next.'
  293. !
  294. basicTypesNumbers
  295. ^ Lesson
  296. title: 'Basic types: Numbers'
  297. contents:
  298. '"You now know how to execute Smalltalk code.
  299. Now let''s talk about basic objects.
  300. 1, 2, 100, 2/3 ... are Numbers, and respond to many messages evaluating mathematical expressions.
  301. Evaluate these ones:"
  302. 2.
  303. (1/3).
  304. (1/3) + (4/5).
  305. (18/5) rounded.
  306. 1 class.
  307. 1 negated.
  308. 1 negated negated.
  309. (1 + 3) odd.
  310. ProfStef next.'
  311. !
  312. basicTypesString
  313. ^ Lesson
  314. title: 'Basic types: Strings'
  315. contents:
  316. '"A String is a collection of characters. Use single quotes to create a String object. Print these expressions:"
  317. ''ProfStef''.
  318. ''ProfStef'' size.
  319. ''abc'' asUppercase.
  320. ''Hello World'' reversed.
  321. "You can access each character using at: message"
  322. ''ProfStef'' at: 1.
  323. "String concatenation uses the comma operator:"
  324. ''ProfStef'', '' is cool''.
  325. ProfStef next.'
  326. !
  327. basicTypesSymbol
  328. ^ Lesson
  329. title: 'Basic types: Symbols'
  330. contents:
  331. '"A Symbol is a String which is guaranteed to be globally unique.
  332. There is one and only one Symbol #ProfStef. There may be several ''ProfStef'' String objects.
  333. (Message == returns true if the two objects are the SAME)"
  334. ''ProfStef'' asSymbol.
  335. #ProfStef asString.
  336. (2 asString) == (2 asString).
  337. (2 asString) asSymbol == (2 asString) asSymbol.
  338. (Smalltalk at: #ProfStef) next.'
  339. !
  340. blocks
  341. ^ Lesson
  342. title: 'Blocks'
  343. contents:
  344. '"Cascade is cool !! Let''s talk about blocks.
  345. Blocks are anonymous methods that can be stored into variables and executed on demand.
  346. Blocks are delimited by square brackets: []"
  347. [Transcript open].
  348. "does not open a Transcript because the block is not executed.
  349. Here is a block that adds 2 to its argument (its argument is named x):"
  350. [:x | x+2].
  351. "We can execute a block by sending it value messages."
  352. [:x | x+2] value: 5.
  353. [Transcript open] value.
  354. [:x | x+2] value: 10.
  355. [:x :y| x + y] value:3 value:5.
  356. [ProfStef next] value.'
  357. !
  358. blocksAssignation
  359. ^ Lesson
  360. title: 'Block assignation'
  361. contents:
  362. '"Blocks can be assigned to a variable then executed later.
  363. Note that |b| is the declaration of a variable named ''b'' and that '':='' assigns a value to a variable.
  364. Select the three lines then Print It:"
  365. |b|
  366. b := [:x | x+2].
  367. b value: 12.
  368. ProfStef next.'
  369. !
  370. conditionals
  371. ^ Lesson
  372. title: 'Conditionals'
  373. contents:
  374. '"Conditionals are just messages sent to Boolean objects"
  375. 1 < 2
  376. ifTrue: [100]
  377. ifFalse: [42].
  378. "Here the message is ifTrue:ifFalse
  379. Try this:"
  380. Transcript open.
  381. 3 > 10
  382. ifTrue: [Transcript show: ''maybe there''''s a bug ....'']
  383. ifFalse: [Transcript show: ''No : 3 is less than 10''].
  384. 3 = 3 ifTrue: [ProfStef next].'.
  385. !
  386. debugger
  387. ^ Lesson
  388. title: 'Debugger'
  389. contents: '"The Debugger may be the most famous tool of Smalltalk environments. It will open as soon as an unmanaged Exception occurs.
  390. The following code will open the debugger.
  391. ***This should be rethought completely***"
  392. '
  393. !
  394. doingVSPrinting
  395. ^ Lesson
  396. title: 'Doing VS Printing: Doing'
  397. contents:
  398. '"Cool !! (I like to say Cooool :) ). You''ve just executed a Smalltalk expression. More precisely, you sent the message ''next'' to
  399. ProfStef class (it''s me !!).
  400. Note you can run this tutorial again by evaluating: ''ProfStef go''.
  401. ''ProfStef previous'' returns to the previous lesson.
  402. You can also Do It using the keyboard shortcut ''CTRL d''
  403. Try to evaluate this expression:"
  404. window alert: ''hello world!!''.
  405. "Then go to the next lesson:"
  406. ProfStef next.'
  407. !
  408. instanciation
  409. ^ Lesson
  410. title: 'Instanciation'
  411. contents:
  412. '"Objects are instances of their class. Usually, we send the message #new to a class for creating an instance of this class.
  413. For example, let''s create an instance of the class Array:"
  414. Array new
  415. add: ''Some text'';
  416. add: 3.;
  417. yourself.
  418. "See the array we''ve created? Actually, #(''Some text'' 3) is just a shorthand for instantiating arrays."
  419. "If we use a variable to keep track of this object, we''ll be able to do stuff with it."
  420. "The following code must be ran all at one, as the ''anArray'' variable will cease to exist once the execution finishes:"
  421. |anArray|
  422. anArray := Array new
  423. add: ''Some text'';
  424. add: 3;
  425. yourself;
  426. Transcript show: anArray; cr.
  427. anArray remove: 3.
  428. Transcript show: anArray; cr.
  429. anArray add: ''Some more text!!''.
  430. Transcript show: anArray; cr.
  431. "I''ll put myself in an instance of a class named Dictionary and go to the next lesson:"
  432. ((Dictionary new add: (''move on!!'' -> ProfStef)) at: ''move on!!'') next'
  433. !
  434. iterators
  435. ^ Lesson
  436. title: 'Iterators'
  437. contents:
  438. '"The message do: is sent to a collection of objects (Array, Dictionary, String, etc), evaluating the block for each element.
  439. Here we want to print all the numbers on the Transcript (a console)"
  440. #(11 38 3 -2 10) do: [:each |
  441. Transcript show: each printString; cr].
  442. "Some other really nice iterators"
  443. #(11 38 3 -2 10) collect: [:each | each negated].
  444. #(11 38 3 -2 10) collect: [:each | each odd].
  445. #(11 38 3 -2 10) select: [:each | each odd].
  446. #(11 38 3 -2 10) select: [:each | each > 10].
  447. #(11 38 3 -2 10) reject: [:each | each > 10].
  448. #(11 38 3 -2 10)
  449. do: [:each | Transcript show: each printString]
  450. separatedBy: [Transcript show: ''.''].
  451. (Smalltalk current classes select: [:eachClass | eachClass name = ''ProfStef'']) do: [:eachProfstef | eachProfstef next].'
  452. !
  453. loops
  454. ^ Lesson
  455. title: 'Loops'
  456. contents:
  457. '"Loops are high-level collection iterators, implemented as regular methods."
  458. "Basic loops:
  459. to:do:
  460. to:by:do"
  461. 1 to: 100 do:
  462. [:i | Transcript show: i asString; cr ].
  463. 1 to: 100 by: 3 do: [:i | Transcript show: i asString; cr].
  464. 100 to: 0 by: -2 do:
  465. [:i | Transcript show: i asString; cr].
  466. 1 to: 1 do: [:i | ProfStef next].'
  467. !
  468. mathematicalPrecedence
  469. ^ Lesson
  470. title: 'Mathematical precedence'
  471. contents:
  472. '"Traditional precedence rules from mathematics do not follow in Smalltalk."
  473. 2 * 10 + 2.
  474. "Here the message * is sent to 2, which answers 20, then 20 receive the message +
  475. Remember that all messages always follow a simple left-to-right precedence rule, * without exceptions *."
  476. 2 + 2 * 10.
  477. 2 + (2 * 10).
  478. 8 - 5 / 2.
  479. (8 - 5) / 2.
  480. 8 - (5 / 2).
  481. ProfStef next.'
  482. !
  483. messageSyntaxBinary
  484. ^ Lesson
  485. title: 'Message syntax: Binary messages'
  486. contents:
  487. '"Binary messages have the following form:
  488. anObject + anotherObject"
  489. 3 * 2.
  490. Date today year = 2011.
  491. false | false.
  492. true & true.
  493. true & false.
  494. 10 @ 100.
  495. 10 <= 12.
  496. ''ab'', ''cd''.
  497. ProfStef next.'
  498. !
  499. messageSyntaxCascade
  500. ^ Lesson
  501. title: 'Message syntax: Cascade'
  502. contents:
  503. '"; is the cascade operator. It''s useful to send message to the SAME receiver
  504. Open a Transcript (console):"
  505. Transcript open.
  506. "Then:"
  507. Transcript show: ''hello''.
  508. Transcript show: ''Smalltalk''.
  509. Transcript cr.
  510. "is equivalent to:"
  511. Transcript
  512. show: ''hello'';
  513. show: ''Smalltalk'' ;
  514. cr.
  515. "You can close the development tools by clicking on the red circle with a cross at the bottom left of the website.
  516. Try to go to the next lesson with a cascade of two ''next'' messages:"
  517. ProfStef'.
  518. !
  519. messageSyntaxCascadeShouldNotBeHere
  520. ^ Lesson
  521. title: 'Lost ?'
  522. contents:
  523. '"Hey, you should not be here !!!!
  524. Go back and use a cascade !!"
  525. ProfStef previous.'.
  526. !
  527. messageSyntaxExecutionOrder
  528. ^ Lesson
  529. title: 'Message syntax: Execution order'
  530. contents:
  531. '"Unary messages are executed first, then binary messages and finally keyword messages:
  532. Unary > Binary > Keywords"
  533. 2.5 + 3.8 rounded.
  534. 3 max: 2 + 2.
  535. (0@0) class.
  536. 0@0 x: 100.
  537. (0@0 x: 100) class.
  538. "Between messages of similar precedence, expressions are executed from left to right"
  539. -12345 negated asString reversed.
  540. ProfStef next.'
  541. !
  542. messageSyntaxExecutionOrderParentheses
  543. ^ Lesson
  544. title: 'Message syntax: Parentheses'
  545. contents:
  546. '"Use parentheses to change order of evaluation"
  547. (2.5 + 3.8) rounded.
  548. (3 max: 2) + 2.
  549. ProfStef next.'
  550. !
  551. messageSyntaxKeyword
  552. ^ Lesson
  553. title: 'Message syntax: Keyword messages'
  554. contents:
  555. '"Keyword Messages are messages with arguments. They have the following form:
  556. anObject akey: anotherObject akey2: anotherObject2"
  557. ''Web development is a good deal of pain'' copyFrom: 1 to: 30
  558. "The message is copyFrom:to: sent to the String ''Web development is a good deal of pain''"
  559. 1 max: 3.
  560. Array with: ''hello'' with: 2 with: Smalltalk.
  561. "The message is with:with:with: implemented on class Array. Note you can also write"
  562. Array
  563. with: ''Hi there!!''
  564. with: 2
  565. with: Smalltalk.
  566. ProfStef perform: ''next''.'
  567. !
  568. messageSyntaxUnary
  569. ^ Lesson
  570. title: 'Message syntax: Unary messages'
  571. contents:
  572. '"Messages are sent to objects. There are three types of message: Unary, Binary and Keyword.
  573. Unary messages have the following form:
  574. anObject aMessage
  575. You''ve already sent unary messages. For example:"
  576. 1 class.
  577. false not.
  578. Date today.
  579. Number pi.
  580. "And of course: "
  581. ProfStef next.'
  582. !
  583. pharoEnvironment
  584. ^ Lesson
  585. title: 'Pharo environment'
  586. contents:
  587. '"Every Smalltalk system is full of objects. There are windows, text, numbers, dates, colors, points and much more. You can interact with objects in a much more direct way than is possible with other programming languages.
  588. Every object understands the message ''explore''. As a result, you get an Explorer window that shows details about the object."
  589. Date today explore.
  590. "This shows that the date object consists of a point in time (start) and a duration (one day long)."
  591. ProfStef explore.
  592. "You see, ProfStef class has a lot of objects. Let''s take a look at my code:"
  593. ProfStef browse.
  594. ProfStef next.'
  595. !
  596. printing
  597. ^ Lesson
  598. title: 'Doing VS Printing: Printing'
  599. contents:
  600. '"Now you''re a Do It master !! Let''s talk about printing. It''s a Do It which prints the result next to the expression you''ve selected.
  601. For example, select the text below, and click on ''PrintIt'':"
  602. 1 + 2.
  603. "As with ''DoIt'', there is also a shortcut to execute this command.
  604. Try CTRL-p on the following expressions:"
  605. Date today.
  606. "The result is selected, so you can erase it using the backspace key. Try it !!"
  607. Date today asDateString.
  608. Date today asTimeString.
  609. ProfStef next.'
  610. !
  611. reflection
  612. ^ Lesson
  613. title: 'Reflection'
  614. contents:
  615. '"You can inspect and change the system at runtime.
  616. Take a look at the source code of the method #and: of the class Boolean:"
  617. (Boolean methodDictionary at: ''and:'') source.
  618. "Or all the methods it sends:"
  619. (Boolean methodDictionary at: ''and:'') messageSends.
  620. "Here''s all the methods I implement:"
  621. ProfStef methodDictionary.
  622. "Let''s create a new method to go to the next lesson:"
  623. |newMethod|
  624. newMethod := Compiler new load: ''goToNextLesson ProfStef next.'' forClass: ProfStef.
  625. ProfStef class addCompiledMethod: newMethod
  626. "Wow!! I can''t wait to use my new method!!"
  627. ProfStef goToNextLesson.'
  628. !
  629. reflectionContinued
  630. ^ Lesson
  631. title: 'Reflection continued'
  632. contents:
  633. '"So cool, isn''t it ? Before going further, let''s remove this method:"
  634. ProfStef class methodAt: #goToNextLesson.
  635. ProfStef class removeCompiledMethod: (ProfStef class methodAt: #goToNextLesson).
  636. ProfStef class methodAt: #goToNextLesson.
  637. "Then move forward:"
  638. ProfStef perform:#next'
  639. !
  640. theEnd
  641. ^ Lesson
  642. title: 'Tutorial done !!'
  643. contents:
  644. '"This tutorial is done. Enjoy programming Smalltalk with JTalk.
  645. You can run this tutorial again by evaluating: ProfStef go.
  646. See you soon !!"
  647. '
  648. !
  649. welcome
  650. ^ Lesson
  651. title: 'Welcome'
  652. contents:
  653. ' "Hello!! I''m Professor Stef.
  654. You must want me to help you learn Smalltalk.
  655. So let''s go to the first lesson. Select the text below and click on the ''DoIt'' button"
  656. ProfStef next.'
  657. ! !