What is the source of the error produced by the following code?
---------- initialize table := OrderedCollection new. "there are 100 entries like what is below" table add: ({ #value->2. #cost->-3. #step->2. #defense->3. #combatMove->7. #fullMove->14. #carry->10. #lift->20. #death->20. #unconscious->11. #woundThreshold->4. #recovery->0.5. #mysticArmor->0. } as: Dictionary). ---------- More than 256 literals referenced. You must split or otherwise simplify this method. The 257th literal is: 4360 ---------- I'm trying to create a data table for a program and I'm wondering if I'm limited to 256 literals per class or method. I tried initilizing the table in multiple methods (setting 50 per method) but get the same error. I'll probably just put the data in a database and do the lookup when needed or load the table from a file. But I wanted to know the source of the problem. Thanks, Robert _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Jul 23, 2007, at 22:47 , Robert Stehwien wrote: > What is the source of the error produced by the following code? > ---------- > initialize > table := OrderedCollection new. > > "there are 100 entries like what is below" > > table add: ({ > #value->2. > #cost->-3. > #step->2. > #defense->3. > #combatMove->7. > #fullMove->14. > #carry->10. > #lift->20. > #death->20. > #unconscious->11. > #woundThreshold->4. > #recovery->0.5. > #mysticArmor->0. > } as: Dictionary). > ---------- > More than 256 literals referenced. > You must split or otherwise simplify this method. > The 257th literal is: 4360 > ---------- > > I'm trying to create a data table for a program and I'm wondering if > I'm limited to 256 literals per class or method. I tried initilizing > the table in multiple methods (setting 50 per method) but get the same > error. The limit is 256 literals per method. However, a literal array is still just one literal. So you can put all your data into one literal if you want: #(( value 2 cost -3 step 2 defense 3 combatMove 7 fullMove 14 carry 10 lift 20 death 20 unconscious 11 woundThreshold 4 recovery 05 mysticArmor 0 ) ( value 2 cost -3 step 2 defense 3 combatMove 7 fullMove 14 carry 10 lift 20 death 20 unconscious 11 woundThreshold 4 recovery 05 mysticArmor 0 ) ) Then just iterate over it (#do: for the outer array, #pairsDo: is handy for the inner) to construct your objects. Btw, you surely would like to make a class and not just use dictionaries ;) - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Robert Stehwien
Robert Stehwien a écrit :
> What is the source of the error produced by the following code? > ---------- > initialize > table := OrderedCollection new. > > "there are 100 entries like what is below" > > table add: ({ > #value->2. > #cost->-3. > #step->2. > #defense->3. > #combatMove->7. > #fullMove->14. > #carry->10. > #lift->20. > #death->20. > #unconscious->11. > #woundThreshold->4. > #recovery->0.5. > #mysticArmor->0. > } as: Dictionary). > ---------- > More than 256 literals referenced. > You must split or otherwise simplify this method. > The 257th literal is: 4360 > ---------- > > I'm trying to create a data table for a program and I'm wondering if > I'm limited to 256 literals per class or method. I tried initilizing > the table in multiple methods (setting 50 per method) but get the same > error. > > I'll probably just put the data in a database and do the lookup when > needed or load the table from a file. But I wanted to know the source > of the problem. > > Thanks, > Robert The limitation is per-method. Beware, message selectors count for 1 literal (except some special selectors) Also Class names or class variables consume 1 slot... There, you have (#OrderedCollection -> OrderedCollection), #new, #add, #->, #as: (#Dictionary -> Dictionary)... There are other limitations, like number of argument per message, number of temporary variables per method, number of instance variables per class, length of blocks in an optimized ifTrue: [] ifFalse [] or [] whileTrue: [] or to:do:[] construct... This is based on the assumption that a Smalltalk method SHOULD be small. You can for example write as a workaround table := Dictionary new. #( #(#value 2) #(#cost 3) #(#etc 0.1) ) do: [:pair | table at: pair first put: pair last]. Nicolas _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Robert Stehwien
Hi, you can simply add this information to a comma or tab delimited file. Then you can simply read this end to populate the instance variable. Otherwise, you can add it to a database like you said and do the lookup when it is necessary. If your goal is to lookup value given its key, why don't you simply use a Dictionary? Just a thought.
Good luck, -Conrad
On 7/23/07, Robert Stehwien
<[hidden email]> wrote: What is the source of the error produced by the following code? _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Bert Freudenberg
Damned, Bert you are really fast today!
Nicolas _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Jul 23, 2007, at 23:36 , nicolas cellier wrote:
> Damned, Bert you are really fast today! Thats the joy of a project where you actually have to wait for compiles to finish ... :-/ - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Bert Freudenberg
> The limit is 256 literals per method. However, a literal array is
> still just one literal. So you can put all your data into one literal > if you want: > > #(( > value 2 > cost -3 > step 2 > defense 3 > combatMove 7 > fullMove 14 > carry 10 > lift 20 > death 20 > unconscious 11 > woundThreshold 4 > recovery 05 > mysticArmor 0 > ) ( > value 2 > cost -3 > step 2 > defense 3 > combatMove 7 > fullMove 14 > carry 10 > lift 20 > death 20 > unconscious 11 > woundThreshold 4 > recovery 05 > mysticArmor 0 > ) ) > > Then just iterate over it (#do: for the outer array, #pairsDo: is > handy for the inner) to construct your objects. Btw, you surely would > like to make a class and not just use dictionaries ;) > 256 literals per method seems find to me, initializing such a large dictionary was unusual for me and something of an experiment (mainly to avoid reading from a file at all). I had the data in YAML that I just wrote a small script to generate smalltalk code from. I didn't make a class mainly because I don't need the data for anything more than lookups dictionaries give me. I'll give your suggestion above a try but might just convert the YAML to XML or CSV and read the table in from the file. Maybe as an array of RecordEntry instead of using a dictionary. I will have a need for a database (or some persistence layer) later in the project, so might just bite the bullet now. Thanks, Robert _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |