LS97 wrote:
@TheSuccessor:
i can try. should be easy.
I know. Should be a 'one line' function. Darned if I can find the smalltalk equivalent of javascripts' 'eval()' anywhere online though. That said, wish you luck.
[Edited by fullmoon to remove mild expletive]
Last edited by fullmoon (2010-12-05 11:59:00)
Offline
TheSuccessor wrote:
LS97 wrote:
@TheSuccessor:
i can try. should be easy.I know. Should be a 'one line' function. * if I can find the smalltalk equivalent of javascripts' 'eval()' anywhere online though. That said, wish you luck.
Compiler evaluate: t1 with: self.
(that was from memory, don't yell at me if it's wrong)
EDIT: I mean
Compiler evaluate: t2 for: self logged: false
Last edited by nXIII (2010-06-20 13:53:54)
Offline
paserra wrote:
Hi,
do someone knows how to implement a routine equivalent to strtok (in c) using squeak?
A similar scratch block cold be useful for parsing list items (loaded from a text file).
Regards,
Pier Andrea.
I've started to program in SmallTalk few days ago: this is my first try to make a block:
This is the block that returns a parsed string (It has 3 argument: 1) the string to tokenize; 2) the chars used as separators; 3) the number of the token to return as result. (a NULL value is returned as error or end-of-tokens).
('strtok %s %s %n' #r #str:tok:num: 'one,two,three' ',' 2)
str: t1 tok: t2 num: t3
| mydata itemnum numX |
mydata < t1 findTokens: t2.
itemnum < mydata size.
t3 < 1 | (t3 > itemnum)
ifTrue: [numX < '']
ifFalse: [numX < mydata at: t3].
^ numX
Sorry for the style, it seems to work. It could be useful for parsing CSV files in Panther. If someone is able to insert the parsed strings directly in a list object it could be great!
Regards,
Pier Andrea.
Offline
LS97 wrote:
Zorbak42 wrote:
Anyone know if it's possible to convert a project made with a mod of Scratch into a .exe and have the mod's extra blocks work? (and if so, how?) I haven't tried, but I assume Jens' Scratch2Exe doesn't work on projects made with mods?
ok!
i'm back and ready to tell you!
take Jens' sratch2exe 'compiler' folder.
go to 'kit'.
this folder is similar to the scratch one, don't you agree?
rename runtime.image to runtime.backup
add you own image and rename it runtime.image
important! this image should be a COPY of the original, not dragged into the folder.
open that image in scratch.exe by dragging it onto it.
open the system browser in your program.
go to ui-panes, frameMorph, menu/button actions, quitScratch, and replace that code withCode:
quitScratch self closeMediaEditorsAndDialogs ifFalse: [^ self]. self stopAll. Smalltalk snapshot: false andQuit: trueand click accept.
save the image, and try it on a project made with your mod!
I tried this with Panther and when I ran the .exe, it opened up an empty, default project. Also, when I pressed the back button in presentation mode, it just goes to the normal Panther window instead of closing it. I've noticed that most mods (including Panther) open an empty project when you try opening a project (by double-clicking the project, not by choosing File > Open...). Is this why it opens an empty project? And why does the back button not close it?
Offline
paserra wrote:
paserra wrote:
Hi,
do someone knows how to implement a routine equivalent to strtok (in c) using squeak?
A similar scratch block cold be useful for parsing list items (loaded from a text file).
Regards,
Pier Andrea.I've started to program in SmallTalk few days ago: this is my first try to make a block:
This is the block that returns a parsed string (It has 3 argument: 1) the string to tokenize; 2) the chars used as separators; 3) the number of the token to return as result. (a NULL value is returned as error or end-of-tokens).('strtok %s %s %n' #r #str:tok:num: 'one,two,three' ',' 2)
str: t1 tok: t2 num: t3
| mydata itemnum numX |
mydata < t1 findTokens: t2.
itemnum < mydata size.
t3 < 1 | (t3 > itemnum)
ifTrue: [numX < '']
ifFalse: [numX < mydata at: t3].
^ numXSorry for the style, it seems to work. It could be useful for parsing CSV files in Panther. If someone is able to insert the parsed strings directly in a list object it could be great!
Regards,
Pier Andrea.
What does it do?
Offline
nXIII wrote:
TheSuccessor wrote:
LS97 wrote:
@TheSuccessor:
i can try. should be easy.I know. Should be a 'one line' function. * if I can find the smalltalk equivalent of javascripts' 'eval()' anywhere online though. That said, wish you luck.
Compiler evaluate: t1 with: self.
(that was from memory, don't yell at me if it's wrong)
EDIT: I meanCode:
Compiler evaluate: t2 for: self logged: false
Thanks nXIII.
By the way, you said at one point something was from memory. That sort of implies you were going to look it up. I'd be interested to see this information if it's online.
Last edited by TheSuccessor (2010-06-21 12:24:45)
Offline
Zorbak42 wrote:
I tried this with Panther and when I ran the .exe, it opened up an empty, default project. Also, when I pressed the back button in presentation mode, it just goes to the normal Panther window instead of closing it. I've noticed that most mods (including Panther) open an empty project when you try opening a project (by double-clicking the project, not by choosing File > Open...). Is this why it opens an empty project? And why does the back button not close it?
yep. sorry. i found a glitch about why it doesnt close. the code i made you edit is to close without asking to save. in ScratchPresenterMorph you hve to change the exitButton's code to quitScratch instead of exitPresentation mode.
That was off my head, i could get it wrong
Offline
TheSuccessor wrote:
nXIII wrote:
TheSuccessor wrote:
I know. Should be a 'one line' function. * if I can find the smalltalk equivalent of javascripts' 'eval()' anywhere online though. That said, wish you luck.Compiler evaluate: t1 with: self.
(that was from memory, don't yell at me if it's wrong)
EDIT: I meanCode:
Compiler evaluate: t2 for: self logged: falseThanks nXIII.
By the way, you said at one point something was from memory. That sort of implies you were going to look it up. I'd be interested to see this information if it's online.
Ah... no, I just look around in the source code a bit; I knew where the method was, but not what the exact method was.
Offline
LS97 wrote:
Zorbak42 wrote:
I tried this with Panther and when I ran the .exe, it opened up an empty, default project. Also, when I pressed the back button in presentation mode, it just goes to the normal Panther window instead of closing it. I've noticed that most mods (including Panther) open an empty project when you try opening a project (by double-clicking the project, not by choosing File > Open...). Is this why it opens an empty project? And why does the back button not close it?
yep. sorry. i found a glitch about why it doesnt close. the code i made you edit is to close without asking to save. in ScratchPresenterMorph you hve to change the exitButton's code to quitScratch instead of exitPresentation mode.
That was off my head, i could get it wrong
You got it right, it exit's Panther rather than just presentation mode, but it still doesn't open the project, just a blank, new one. Any ideas?
Offline
Billybob-Mario wrote:
paserra wrote:
paserra wrote:
Hi,
do someone knows how to implement a routine equivalent to strtok (in c) using squeak?
A similar scratch block cold be useful for parsing list items (loaded from a text file).
Regards,
Pier Andrea.I've started to program in SmallTalk few days ago: this is my first try to make a block:
This is the block that returns a parsed string (It has 3 argument: 1) the string to tokenize; 2) the chars used as separators; 3) the number of the token to return as result. (a NULL value is returned as error or end-of-tokens).('strtok %s %s %n' #r #str:tok:num: 'one,two,three' ',' 2)
str: t1 tok: t2 num: t3
| mydata itemnum numX |
mydata < t1 findTokens: t2.
itemnum < mydata size.
t3 < 1 | (t3 > itemnum)
ifTrue: [numX < '']
ifFalse: [numX < mydata at: t3].
^ numXSorry for the style, it seems to work. It could be useful for parsing CSV files in Panther. If someone is able to insert the parsed strings directly in a list object it could be great!
Regards,
Pier Andrea.What does it do?
this is my last version of the block called "split". It splits a string in substrings using a separator ant puts the resulting strings in a list.
('split %s using %s in %L' #- #str:tok:num: '1,2,3' ',' 'list')
str: t1 tok: t2 num: t3
| mydata value datasize count |
mydata := t1 findTokens: t2.
datasize := mydata size.
count := 0.
[count < datasize]
whileTrue:
[count := count + 1.
value := mydata at: count.
self append: value toList: t3]
Regards,
Pier Andrea.
Last edited by paserra (2010-06-22 01:52:20)
Offline
@Pier Andrea,
That's some nice code you have here! well done!
Offline
Ive already done that...
Ask Panther if you dont belive me!
Offline
johnnydean1 wrote:
Ive already done that...
Ask Panther if you dont belive me!
No need to be like that about it. You both came up with it independently, and there's no need to brag about coming up with it first.
Offline
johnnydean1 wrote:
Ive already done that...
Ask Panther if you dont belive me!
What have you done?
Offline
LS97 wrote:
@Pier Andrea,
That's some nice code you have here! well done!
Thank you LS97, this is my first try. Now I can read text files and parsing strings.
I've tryed to insert the block split code in Panther and if I have a text file with text lines ending with CR (ascii= 13 or CRLF ascii= 13+10) , using the split block with the following arguments:
1) readfile block
2) newline char (or CRLF chars)
3) mylist
I can load the entire file directly in a list in one shot! It is great!
I hope this could be useful also for other users.
Regards.
Pier Andrea.
Offline
johnnydean1 wrote:
Ive already done that...
Ask Panther if you dont belive me!
Dear johnnydean1,
I asked help few post ago in this topic (see my previous messages #721 and #723) about my need to have a strtok block (called now split). I didn' found specific code in the forum nor received a response from Squeak developers. Than I've developed myself the code and posted here for everyone interested in it. Please, post me the link of your code I'm sure it is better than mine (I'm a c programmer, I've starting to program in Squeak 4 days ago).
Regards,
Pier Andrea.
Offline
I dont have the code, youll have to ask Panther. Its called:
Decompile %s with %s as breaker
so....
BTW, yours is better!
Offline
Another small piece of code. This block is an analog of "join" block that merges two strings. The only difference is the variable number of arguments.
('concat %X' #r #concat:)
concat: t1
| listlines myline merge count |
listlines _ self lineCountOfList: t1.
count _ 0.
merge _ ''.
[count < listlines]
whileTrue:
[count _ count + 1.
myline _ self getLine: count ofList: t1.
merge _ self concatenate: merge with: myline].
^ merge
Let me know what you think about.
Regards,
Pier Andrea.
p.s. the only limitation of the routine is the impossibility to include newline characters in the resulting string because of the use of list lines.
Last edited by paserra (2010-06-22 17:28:21)
Offline
LS97 wrote:
The 'showing?' block
This is an easy one. It gives a boolean response (True/False) of whether the sprite is showing or not.
Like before, copy this code into the 'looks' section of blockSpecs in ScratchSpriteMorphCode:
('showing?' #b #getHidden)then go to instance, 'looks ops' and replace the code in 'hide' with the code below (by the way, you're not deleting the hide block).
Code:
getHidden self isHidden = false ifTrue: [^ true]. ^ falseThen right-click, clik accept and (maybe) type your initials. et voilà, you have your 'showing?' block up and ready.
It is easier to do this one using
('showing?' #b #isHidden)
. This means that you don't have to make a function, just add the block spec!
Offline
billyedward wrote:
LS97 wrote:
The 'showing?' block
This is an easy one. It gives a boolean response (True/False) of whether the sprite is showing or not.
Like before, copy this code into the 'looks' section of blockSpecs in ScratchSpriteMorphCode:
('showing?' #b #getHidden)then go to instance, 'looks ops' and replace the code in 'hide' with the code below (by the way, you're not deleting the hide block).
Code:
getHidden self isHidden = false ifTrue: [^ true]. ^ falseThen right-click, clik accept and (maybe) type your initials. et voilà, you have your 'showing?' block up and ready.
It is easier to do this one using
Code:
('showing?' #b #isHidden). This means that you don't have to make a function, just add the block spec!
OMG!!!!!!!!!! WHY WON'T YOU KEEP MAKING MORE VERSIONS OF STREAK!?!?!?!?
Offline
billyedward wrote:
LS97 wrote:
The 'showing?' block
This is an easy one. It gives a boolean response (True/False) of whether the sprite is showing or not.
Like before, copy this code into the 'looks' section of blockSpecs in ScratchSpriteMorphCode:
('showing?' #b #getHidden)then go to instance, 'looks ops' and replace the code in 'hide' with the code below (by the way, you're not deleting the hide block).
Code:
getHidden self isHidden = false ifTrue: [^ true]. ^ falseThen right-click, clik accept and (maybe) type your initials. et voilà, you have your 'showing?' block up and ready.
It is easier to do this one using
Code:
('showing?' #b #isHidden). This means that you don't have to make a function, just add the block spec!
no. if you would have actually looked at my code, you would have seen that isHidden reports if it's 'hidden?', not 'showing?'. so you have to make an instance for it to make life easier.
Offline
LS97 wrote:
nXIII wrote:
LS97 wrote:
@nXIII:
thanks!
although, i have one more question. how do you make the nested blocks repeat until a boolean comes true?That's an already-defined special-form, I believe #doWhile, maybe?
hmm... i suppose so.
i'll play around with those forms.
nXIII,
back to page 24 in this thread.
you once told me that the function for the 'When %b is true' block was stored in a special form called doWhile. When i became i little better at squeak, i saw that in fact that's simply for a c block called 'do while %b', which was later replaced by the 'do until %b'.
it's exactly the same thing, but one of them waits until the condition is true, and one until the condition is false. Any other help?
PS. about the special forms for C blocks. How do you take the first argument for the block from the array it's stored into?
Offline
*bump*
please look at post 749
Offline
BUMP! look at post 749!
Offline