The array is expecting a literal value
set chrom [forage_min forage_rate share_min share_rate mating_treshold]
print chrom
How can I handle it? I really don't understand arrays in Netlogo.
(You speak of "arrays" in your question, but I think you mean "lists". It is possible to use arrays in NetLogo via the array extension, but unless you have very specific needs, that's probably not what you want. So, assuming that you are trying to create a list:)
The square bracket syntax for declaring lists only works with "literal" values, e.g., raw strings or numbers. If you want to build a list out of variables or more complex expressions, you need to use the list primitive. In your case, that would be something like:
set chrom (list forage_min forage_rate share_min share_rate mating_treshold)
I would encourage you to read the Lists section of the NetLogo programming guide.
Related
I've tried searching this but have yet to find something that suits anything close to my needs. I'm trying to create a Autocad LISP that takes a text file, which is a list of comma-separated values, and place a block at coordinates defined by the list. BUT, only for items on the list where the last entry starts with "HP"
So that's sounds a bit complex, but the text file is basically a UTM survey output, and looks like this:
1000,Easting,Northing,Elevation,Identifier
1001,Easting,Northing,Elevation,Identifier
Etc.
The identifier is a variety of values, but I want to extract the Northing,Easting,Elevation, and insert a block (this last part I've got) at that location when the identifier begins with "HP". The list can be long and the number of HPs can be 1 or 5000. I'm assuming there's a "for x=1:end, do" type of loop than can be made that reuses the same variables over and over.
I'm a newbie to LISP so I'm stuck in that spot between "here are I've-never-programmed-before tutorials to make hello world" and "here is a library of the 3000 different commands in alphabetical order"
I believe the functions you are needing to solve this question are open, read-line or read-char, close,strlen, and substr. The first four functions relate to AutoLisp writing and reading a file. The last two functions manipulate the string variables that were pulled from the file. With them, you can find the "HP" within the text. To loop through the same code, three come to my mind: repeat, while, and foreach.
For a list of variables to quickly reference with their descriptions, here's a good starting point. This particular page has the information broken up by category instead of alphabetical order.
https://help.solidworks.com/2022/English/api/draftsightlispreference/html/lisp_functions_overview.htm
Here are a few tutorials where AutoLisp code is used to write and read other files:
https://www.afralisp.net/autolisp/tutorials/file-handling.php
https://www.afralisp.net/autolisp/tutorials/external-data.php
Lastly, here's an example of AutoLisp writing and reading attributes from and to blocks.
https://github.com/GitHubUser5376/AttributeImportExport
You can use Lee-Mac's Reacd-CSV function to get a list of the csv values.
And for the "HP" detection yes you might have to go through(using loop options mentioned above like while, repeat,foreach) each and use
(substr Identifier 1 2)
to validate
It is known that default printer can be confusing wrt lists because of no output for empty lists and 3 different notations being mixed (, vs (x;y;z) vs 1 2 3) and not obvious indentation/columnization (which is apparently optimized for table data). I am currently using -3! but it is still not ideal.
Is there a ready-made pretty-printer that has consistent uniform output format (basically what I am used to in any other language where list is not special)?
I've started using .j.j for string outputs in error messages more recently in preference to -3!. Mainly I think it is easier to parse in a text log, but also doesn't truncate in the same way.
It still transforms atoms and lists differently so it might not exactly meet your needs, if you really want that you could compose it with the old "ensure this is a list" trick:
myPrinter:('[.j.j;(),])
You might need to supply some examples to better explain your issues and your use-case for pretty-printing.
In general -3! is the most clear visual representation of the data. It is the stringified equivalent to another popular display method which is 0N!.
The parse function is useful for understanding how the interpreter reads/executes commands but I don't think that will be useful in your case
I have a method in Scala that returns a tuple, let's say the method is called 'test'. Then I want to do
val (X,Y) = test()
However, the pattern-matching only works in Scala when the variable names are lowercase, ie:
val(_X,_Y) = test(); val X = _X; val Y = _Y
... works ok, but is ugly, and not terse. Since X and Y are matrices, I don't really want to have to use lowercase variables. (In scipy and matlab, I wouldn't have such a restriction for example).
I think there is some way to make sure lowercase variables behave like uppercase ones, ie by doing `x`. Perhaps there is some way of making uppercase variables behave like lowercase ones? So, that is my question: is there some way of pattern matching directly into uppercase variables in Scala?
The short answer is don't.
Syntax conventions make your code readable and understandable for others. Scala's convention is that variables start with lower-case and constants and classes start with upper-case. By violating this, not only you get problems like pattern-matching issues, your code becomes less readable. (Believe me, if you ever have to read code written by someone else who didn't care for such conventions, you'll be cursing that person.)
If you want to emphasize that the variables are matrices, I suggest you to use xMatrix and yMatrix or something like that. This will make clear that they're variables and that they represent matrices.
Or create a convention specific to your project that all matrix variables will end with let's say "M", like xM and yM.
It's worth typing a few more characters if it makes your code readable.
There is no way to do this and there shouldn't be. You already have the type of the variable to tell you that it is a matrix, so there is no need to make variable names uppercase.
I can write:
x\_m<TAB> = 5
to get x subscript m as a variable name in Julia. What if I want to subscript a word instead of a single character? This
x\_max<TAB> = 5
doesn't work. However,
x\_m<TAB>\_a<TAB>\_x<TAB> = 5
does work, it's just very uncomfortable. Is there a better way?
As I noted in my comment, not all ASCII characters exist as unicode super- or sub-scripts. In addition, another difficulty in generalizing this tab completion will be determining what \_phi<TAB> should mean: is it ₚₕᵢ or ᵩ? Finally, I'll note that since these characters are cobbled together from different ranges for different uses they look pretty terrible when used together.
A simple hack to support common words you use would be to add them piecemeal to the Base.REPLCompletions.latex_symbols dictionary:
Base.REPLCompletions.latex_symbols["\\_max"] = "ₘₐₓ"
Base.REPLCompletions.latex_symbols["\\_min"] = "ₘᵢₙ"
You can put these additions in your .juliarc.jl file to load them every time on startup. While it may be possible to get a comprehensive solution, it'll take much more work.
Since Julia 1.6 this works for subscripts (\_) and superscripts(\^) in the Julia REPL.
x\_maxTAB will print out like this: xₘₐₓ.
x\^maxTAB will print out like this: xᵐᵃˣ.
I require an approximate string matching function for Matlab. I found out that the Bioinformatics toolbox has the Needleman–Wunsch algorithm by calling nwalign(). The only problem is that it only works with amino acid sequences. So when I try compare strings with numbers and other symbols, I get an error saying: "Both sequences must be amino acids."
Is there a way to allow the nwalign() function to accept any type sequence or is there another matlab function which can perform approximate string matching which is not limited to bioinformatics?
This has been discussed in this thread
It explains how to use a non-documented function to perform alignments with symbols other than aminoacids or nucleotides.
Have a look at python's nwalign() .
http://pypi.python.org/pypi/nwalign
It seems to take strings as arguments (yet to look at the source), so if you have numpy sequences or lists, you may need to convert them.
You can try in this way :
[Score,Align] =nwalign(Seq1,Seq2,'Alphabet','NT')
In this way you can align two nucleotidic sequences.
Which kind of scoring matrix are you going to use?