2
votes

Is it possible to use an uninitialized variable as a function argument? For an assignment, I have to use the CLOS to write a semantic network system, and my professor included a test function to test our output, and one of them specifies:

(print (def-concept Human)),

which implies passing the argument Human to the function def-concept. When running this test function, I cannot get away from the error (in Allegro CL):

Error: Attempt to take the value of the unbound variableHUMAN'.`

As this is the first function in the test, there is no initializing of any variables before this. Is there any way to get around passing an uninitialized variable as an argument of a function?

Thanks in advance.

1
It might be useful to ask your professor for help. - Rainer Joswig
unfortunately, it honestly would/has not. - TNC
You can pass in a symbol, which may not have any binding whatsoever, and attempt to retrieve its bindings inside your function. That said, could you not initialise first? - Marcin
Is it even possible to pass in a symbol? I cannot even get into the function because the error stops me as soon as it sees that the argument is unbound. - TNC
Are you sure def-concept is a function? Maybe it's a macro? What's the answer of (describe 'def-concept)? - Miron Brezuleanu

1 Answers

4
votes

It is not possible to use an unitialized value as a function argument in a regular Common Lisp function call. Common Lisp uses eager evaluation: argument expressions are reduced to their values before the function call takes place.

I suspect maybe you don't exactly understand the structure of the homework assignment.

If def-concept is a function which expects a value, and human is not defined, you simply cannot test that function.

Perhaps you are expected to define the variable human and then load the file containing (print (def-concept human)).

Just because there is nothing prior to that form in the same file doesn't mean that no prior evaluation is possible. Other files can be loaded before that file, or forms evaluated in the listener.