This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#176 2011-06-02 19:23:20

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Xenon Inc. Developers' Thread

Implied multiplication?

Code:

If (check code here)
[set (listCheck) to 1]
[set (iterationCheck) to 1]
[set (currentItem) to [(item (currentTotal.Iteration#) of [allTerms]] ]
Repeat until <(done?) = 1>

If <<(currentItem) > 0> and <(currentItem) < 11>>
[change (iterationCheck) by 1]
If <item ((listCheck) + 1 ) of [allTerms]> = [(]
[insert [*] at ((listCheck) + 1) of [allTerms]]
[set (done?) to 1]
if <item ((listCheck) - 1) of [allTerms]> = [)]
[insert [*] at ((listCheck) - 1) of [allTerms]]
[set (done?) to 1]
endIf
if <(iterationCheck> = 10> 
[set (done?) to 1]
endIf
[change (listCheck) by 1]
endIf
If <(currentItem) = [)]>
[if <item ((listCheck) + 1) of [allTerms] = [(]
[insert [*] at ((listCheck) + 1) of [allTerms]
[set (done?) to 1]
else

endif

Hold on, my code is messed up...

EDIT: Feel free to edit, i stil lthink its messed up, but go ahead and figure it out...

Last edited by bbbeb (2011-06-03 18:27:31)


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#177 2011-06-03 06:30:02

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Xenon Inc. Developers' Thread

I'm submitting Xenon here.

Offline

 

#178 2011-06-03 14:17:35

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Xenon Inc. Developers' Thread

BTW Hardmath, I have been a member before, but I went Inactive. Am i not a member? (I contributed code!  big_smile )


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#179 2011-06-03 18:20:16

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

@bbbeb: Hardmath123 is gone for a bit of time because his school just started up (mine just ended).  Concerning your code: you don't want it always to insert a * after a (.  Consider 5 * (2 + 3).

You only want a * between a left parenthesis ) and a right parenthesis (

(5+2)(2+3)

or between a number and a right parenthesis (

5(2+3)

or between a left parenthesis ) and a number

(2+3)5

Offline

 

#180 2011-06-03 18:21:13

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Xenon Inc. Developers' Thread

Oh. Okay. Editing code.  big_smile

Done.  big_smile

Last edited by bbbeb (2011-06-03 18:27:45)


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#181 2011-06-03 20:52:55

hpotter134
Scratcher
Registered: 2010-02-21
Posts: 100+

Re: Xenon Inc. Developers' Thread

*Sigh of relief* School's out! I'll be able to do some more now. I've been checking this topic often (but wasn't posting), and I like what I see, but who's doing the implied multiplication? scratcher7_13, amcerbu, or bbbeb?

Current status: Awaiting my part, as soon as implied multiplication is out of the way.

Oh, one thing:

amcerbu wrote:

... make sure that negative signs (-x) are converted to "-1*x".  So, -4 will become "-1*4".  That will clear up some problems later in the execution.

Wouldn't changing it to "-1*4" be inserting yet another negative (-1)? Wouldn't it be easier to change it to "0-4"?


http://i45.tinypic.com/fxgtvc.png

Offline

 

#182 2011-06-03 22:06:01

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

@hpotter134- Sorry, I don't think that will work anyway.  The program must distinguish between something like 5 - 4 and 5 * - 4. 

5 - 4 would become 5 0 - 4 or 5 (- 1 * 4), instead of 5 + 0 - 4. 

I'm not exactly sure how to deal with this. 

Supposedly (according to a post by Hardmath123), the implied multiplication job is in my hands.  However, if bbbeb wants to do it, I'm fine with that.  scratcher7_13 quit/went inactive.  We ought to discuss some code in-forum so that someone can later go straight to Scratch. 

@everyone: If you have any ideas at all about dealing with implied multiplication, post them in a [code] box.

Last edited by amcerbu (2011-06-03 22:08:31)

Offline

 

#183 2011-06-03 22:15:27

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Xenon Inc. Developers' Thread

I did the implied multiplication, I think i got it..... Just rename the variables and lists accordingly.  tongue


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#184 2011-06-04 11:52:55

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

Can we see the pseudo code?

Offline

 

#185 2011-06-04 14:40:59

hpotter134
Scratcher
Registered: 2010-02-21
Posts: 100+

Re: Xenon Inc. Developers' Thread

amcerbu wrote:

@hpotter134- Sorry, I don't think that will work anyway.  The program must distinguish between something like 5 - 4 and 5 * - 4. 

5 - 4 would become 5 0 - 4 or 5 (- 1 * 4), instead of 5 + 0 - 4. 

I'm not exactly sure how to deal with this. 

Supposedly (according to a post by Hardmath123), the implied multiplication job is in my hands.  However, if bbbeb wants to do it, I'm fine with that.  scratcher7_13 quit/went inactive.  We ought to discuss some code in-forum so that someone can later go straight to Scratch. 

@everyone: If you have any ideas at all about dealing with implied multiplication, post them in a [code] box.

Hmm...maybe the 5*-4 shouldn't be allowed, i.e. it should cause an error, so the user would be forced to place the -4 in parenthesis, making it 5*(-4), which becomes 5*(0-4), and voila.

So unless the previous item is either a number or a close parenthesis ')', a zero should be inserted before the '-'. Make sense?


http://i45.tinypic.com/fxgtvc.png

Offline

 

#186 2011-06-04 15:12:20

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

Yeah, that sounds like it would work.  So, negative terms must be presented within parentheses, and a zero is inserted only if the negative term is isolated. 

Code:

5-3     good
(5)-3   good
5*-3    bad, user should replace with
5*(-3)  programmed to be replaced with
5*(0-3)

Last edited by amcerbu (2011-06-04 15:21:06)

Offline

 

#187 2011-06-05 00:03:05

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Xenon Inc. Developers' Thread

amcerbu wrote:

Can we see the pseudo code?

Edited into original  wink


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#188 2011-06-05 02:19:11

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

Good!  But why do you limit the length of the sequence to 10?

Offline

 

#189 2011-06-05 02:41:30

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Xenon Inc. Developers' Thread

amcerbu wrote:

Good!  But why do you limit the length of the sequence to 10?

Its the current character- it detects 0-9 (and 10, idk why)

as in the current digit, not the sequence.


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#190 2011-06-05 18:10:35

hpotter134
Scratcher
Registered: 2010-02-21
Posts: 100+

Re: Xenon Inc. Developers' Thread

bbbeb wrote:

amcerbu wrote:

Good!  But why do you limit the length of the sequence to 10?

Its the current character- it detects 0-9 (and 10, idk why)

as in the current digit, not the sequence.

Oh! It took me about ten read-throughs to get it, so you are checking that the item is a number, yes?

I think the whole thing might be much faster if we "tokenise" it. In the original parsing (scimonster's code), we could also record the item type of each item in a separate list, where each item in scimonster's generated Input list has a corresponding "token" in the other list. This way, we can figure out the type once, and any subsequent scripts will look at the tokens list rather than figure out the type again. So

Code:

currentItem = index of this item in the inputList
if <(item: currentItem of: tokenList) = 'num'>
//perform action

Instead of doing weird stuff like checking if the number is a digit, because the way scimonster made it, bbbeb, it doesn't have to be a digit, it could be much larger.


http://i45.tinypic.com/fxgtvc.png

Offline

 

#191 2011-06-05 18:27:01

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Xenon Inc. Developers' Thread

hpotter134 wrote:

bbbeb wrote:

amcerbu wrote:

Good!  But why do you limit the length of the sequence to 10?

Its the current character- it detects 0-9 (and 10, idk why)

as in the current digit, not the sequence.

Oh! It took me about ten read-throughs to get it, so you are checking that the item is a number, yes?

I think the whole thing might be much faster if we "tokenise" it. In the original parsing (scimonster's code), we could also record the item type of each item in a separate list, where each item in scimonster's generated Input list has a corresponding "token" in the other list. This way, we can figure out the type once, and any subsequent scripts will look at the tokens list rather than figure out the type again. So

Code:

currentItem = index of this item in the inputList
if <(item: currentItem of: tokenList) = 'num'>
//perform action

Instead of doing weird stuff like checking if the number is a digit, because the way scimonster made it, bbbeb, it doesn't have to be a digit, it could be much larger.

Can you please explain in detail? I'm trying to figure out what tokens are, but the concept to me is confusing.


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#192 2011-06-05 19:34:51

hpotter134
Scratcher
Registered: 2010-02-21
Posts: 100+

Re: Xenon Inc. Developers' Thread

bbbeb wrote:

hpotter134 wrote:

...

Can you please explain in detail? I'm trying to figure out what tokens are, but the concept to me is confusing.

Sorry if I wasn't clear.

So, when we process the user's input, we currently make one list. So 2(5+13) would be parsed into

2
(
5
+
13
)

right? But each item is a certain type, in this case its either a number, an open parenthesis, a close parenthesis, or an operator. Later in the program, we will want to do something to each item in the list above depending on its type, as in, we want to know what type of item each item is. Make sense so far?

Figuring out the type of item could be tedious, and could include scanning multiple lists and other yuck. So, if we have to figure out the type of an item more than once, the program will be significantly bulkier and slower.

So my suggestion is that we figure out the type of each item at the very beginning, and parse it into two list, not one. So it becomes:

Code:

inputList   tokenList
2           number
(           open parenthesis
5           number
+           operator
13         number
)            close parenthesis

So later scripts would just look at tokenList to see the type, rather than checking what type the item is in the first list. This will allow us to get really specific with types (such func3 for a function with three arguments, or something like that), without slowing the program down too much.


http://i45.tinypic.com/fxgtvc.png

Offline

 

#193 2011-06-05 19:45:22

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: Xenon Inc. Developers' Thread

hpotter134 wrote:

bbbeb wrote:

hpotter134 wrote:

...

Can you please explain in detail? I'm trying to figure out what tokens are, but the concept to me is confusing.

Sorry if I wasn't clear.

So, when we process the user's input, we currently make one list. So 2(5+13) would be parsed into

2
(
5
+
13
)

right? But each item is a certain type, in this case its either a number, an open parenthesis, a close parenthesis, or an operator. Later in the program, we will want to do something to each item in the list above depending on its type, as in, we want to know what type of item each item is. Make sense so far?

Figuring out the type of item could be tedious, and could include scanning multiple lists and other yuck. So, if we have to figure out the type of an item more than once, the program will be significantly bulkier and slower.

So my suggestion is that we figure out the type of each item at the very beginning, and parse it into two list, not one. So it becomes:

Code:

inputList   tokenList
2           number
(           open parenthesis
5           number
+           operator
13         number
)            close parenthesis

So later scripts would just look at tokenList to see the type, rather than checking what type the item is in the first list. This will allow us to get really specific with types (such func3 for a function with three arguments, or something like that), without slowing the program down too much.

Oohhhhh!
Thanks!
I should do a runthrough of my code to optimize it, but instead i'm just going to copy it into this and optimize it there so I have a backup....

Code:

If (check code here)
[set (listCheck) to 1]
[set (iterationCheck) to 1]
[set (currentItem) to [(item (currentTotal.Iteration#) of [allTerms]] ]
Repeat until <(done?) = 1>

If <item (currentItem) of [tokenList] = [number]>
If <item ((listCheck) + 1 ) of [inputList]> = [(]
[insert [*] at ((listCheck) + 1) of [inputList]]
[set (done?) to 1]
if <item ((listCheck) - 1) of [inputList]> = [)]
[insert [*] at ((listCheck) - 1) of [allTerms]]
[set (done?) to 1]
endIf
[change (listCheck) by 1]
endIf
If <(currentItem) = [)]>
[if <item ((listCheck) + 1) of [tokenList] = [(]
[insert [*] at ((listCheck) + 1) of [tokenList]
[set (done?) to 1]
else
endif
endif

Last edited by bbbeb (2011-06-05 19:51:25)


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#194 2011-06-06 00:12:29

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Xenon Inc. Developers' Thread

Good!  In the actual program's token list, numbers can be represented by n, operators by o, and parentheses by p.

Offline

 

#195 2011-06-06 04:15:25

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Xenon Inc. Developers' Thread

amcerbu wrote:

Good!  In the actual program's token list, numbers can be represented by n, operators by o, and parentheses by p.

Actually, I would recommend N(umber), O(perator) C(lose parentheses), O(pen parentheses).

Offline

 

#196 2011-06-06 07:12:10

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Xenon Inc. Developers' Thread

In case of 5*-3, make the list item (3) into (-3)! So simple!
List:
5
*
-
3

to:

List:
5
*
-3


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#197 2011-06-06 07:15:29

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Xenon Inc. Developers' Thread

I meant to say that!
You're completely right.  big_smile

Offline

 

#198 2011-06-06 08:58:55

hpotter134
Scratcher
Registered: 2010-02-21
Posts: 100+

Re: Xenon Inc. Developers' Thread

What's the fastest and most failproof method of figuring out what "type" an item is? We could use this for starters, but what then?


http://i45.tinypic.com/fxgtvc.png

Offline

 

#199 2011-06-06 12:51:25

applejack
Scratcher
Registered: 2010-03-23
Posts: 100+

Re: Xenon Inc. Developers' Thread

Umm... But now you have two "O"s! I would suggest "S" for starting parenthesis and "E" for end parenthesis, just plain old "(" and ")", or a capital "O" for open parenthesis and a lower case "o" for operators. [offTopic]I'm so happy! I have a website making camp today!!!  big_smile  [/offTopic]

scimonster wrote:

amcerbu wrote:

Good!  In the actual program's token list, numbers can be represented by n, operators by o, and parentheses by p.

Actually, I would recommend N(umber), O(perator) C(lose parentheses), O(pen parentheses).


http://i.imgur.com/zKzps.png
http://blocks.scratchr.org/API.php?action=onlineStatus&amp;type=square&amp;user=applejack -I'm http://blocks.scratchr.org/API.php?action=onlineStatus&amp;type=text&amp;user=applejack

Offline

 

#200 2011-06-06 12:54:06

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Xenon Inc. Developers' Thread

applejack wrote:

Umm... But now you have two "O"s! I would suggest "S" for starting parenthesis and "E" for end parenthesis, just plain old "(" and ")", or a capital "O" for open parenthesis and a lower case "o" for operators. [offTopic]I'm so happy! I have a website making camp today!!!  big_smile  [/offTopic]

scimonster wrote:

amcerbu wrote:

Good!  In the actual program's token list, numbers can be represented by n, operators by o, and parentheses by p.

Actually, I would recommend N(umber), O(perator) C(lose parentheses), O(pen parentheses).

It's really hard to do case sensing, so yeah, ( & ).  smile
EDIT: 200th post on this topic!

Last edited by scimonster (2011-06-06 12:54:45)

Offline

 

Board footer