LPUT expected input to be a list but got the number 0 instead.

327 views
Skip to first unread message

parichehr mandegaran

unread,
Mar 1, 2021, 7:51:44 AM3/1/21
to netlogo-users
hi 
What's wrong with that?
to create-list-all-year-precipitation
  file-open "PCPyear.txt"
  let Y 2002
  while [Y <= 2017]
  [
    let line file-read-skipComments
    set list-all-year-precipitation lput (item 0 read-from-string item 1 line ) list-all-year-precipitation
    set Y Y + 1
  ]
  file-close


end
to-report file-read-skipComments
  let rep []
  while [(not file-at-end?) and (empty? rep)] [
    let line file-read-line
    if(length line > 0) [
      if ((first line != ";") and (first line != "#") and (first line != "%")) [
        if (position " " line != false) [
          set rep (list (substring line 0 (position " " line)) (substring line ((position " " line) + 1) (length line)))

        ]
      ]
    ]
  ]
  report rep
end



i have this error

LPUT expected input to be a list but got the number 0 instead.

Charles Staelin

unread,
Mar 1, 2021, 8:20:03 AM3/1/21
to netlogo-users
I suspect that the problem is that list-all-year-precipitation has not been initialized to an empty list.  Since you have used "set" on it, I assume it is a global variable and global variables are initialized by NetLogo to zeros.  If you add the line 
set list-all-year-precipitation [ ] 
right before your "while" statement, it will tell NetLogo that the variable should begin as an empty list, not a number.  It's often a good idea to initialize all globals in your setup procedure to make their initialization explicit.

Charles
Reply all
Reply to author
Forward
0 new messages