joybee wrote:(defstruct employee first_name last_name mid_name birthday start_date title)
(defparameter employee_list (make-array 0 :adjustable t :fill-pointer 0))
(defun read_list (filename)
)
(defun print_list ())
Question:
How can I assigned the values from the text string to the employee structure and create employee array?
A few things.
An array seems like an odd choice for this program, especially for a prototype. I would think that lists will do fine for prototyping, and that any demanding application would be better served by a structure chosen for the type of lookups you will need to do.
You might also run into some trouble saving your list of employees in a variable. It could easily happen that you don't reset this variable between runs, and you end up thinking that read_list (or "read-list", as most of us would name it... well, I'd probably call it "employees-from" or something) is being properly updated, when in fact it contains garbage data from a previous run. This could be obvious to you, but I mention it because you may be used to working in a non-interactive environment where each run starts with a clean slate. Since you don't shut down your Lisp image between runs, any state you don't reset is retained — which is mostly a great thing, but can lead to silly errors. Personally, I would make read_list simply construct and return a list, and forget about side-effects. Since Lisp has a garbage collector, you can do this any time you want with no worries about memory leaks. Then you can test it by running (print_list (read_list)) at the REPL. Once you're sure read_list is working, you may want to save the data in a global variable for easy interactive testing purposes, but even so, you'll be better off if you pass that data as an argument rather than making print_list check out some hard-coded variable. (print_list employee_list), right?
As for doing the actual work, it depends, like qbg said, on your file format. Storing employee data as s-expressions is easiest. Then you can just READ from the file after setting *READ-EVAL* to nil to prevent code injection, if that's an issue. You'll get lists back, which are just about the easiest thing in the world to work with. If you've already got some files in another format, you'll just have to read lines as strings and parse them by hand.
I suspect print_list is going to be superfluous. The built-in PRINT function can print arrays and lists just fine. Lisp won't print anything interesting for your employee structure, but you can tell it what you want to see when you define the structure. Of course if there is a specific print format you'd like to see you'll need to write print_list.