aya_kh
aya_kh

Reputation: 49

how to rewrite this code in netlogo 6.1.1?

i'm transfering my code from net logo 3.1.5 to netlogo 6.1.1. i couldn't know how to make this line works in the new version. this is the code line in netlogo 3.1.5 and it works:

set d0 sort-by [length ?1 <= length ?2] d0

this line means sort the list d0 from the little to the big value and when finishing put the result in d0 again.

the [length ?1 <= length ?2] meanse compare the value of the temporary variable named ?1 with the value of temporary variable named ?2

in netlogo 6.1.1 it tells me that nothing named ?1 has been defined

can you please help me !

Upvotes: 1

Views: 55

Answers (1)

JenB
JenB

Reputation: 17678

The NetLogo dictionary is available at https://ccl.northwestern.edu/netlogo/docs/dictionary.html It is a good starting point for finding the new syntax of any of the primitives you will have in your v3 code. In this case, one of the examples for sort-by is to sort on the length of a string. I'm guessing that the contents of d0 are strings - it' not clear from your question because you talk about sorting from small to large values but you have length in your code.

Assuming that you are sorting by length, here is the exact example as given in the dictionary:

show sort-by [ [string1 string2] -> length string1 < length string2 ] ["Grumpy" "Doc" "Happy"]

gives ["Doc" "Happy" "Grumpy"]

Translating to your case, you probably want:

set d0 sort-by [ [s1 s2] length s1 <= length s2] d0

Upvotes: 4

Related Questions