TrySmalltalk.st 18 KB

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