[Ecls-list] A cl_funcall and cl_safe_eval question.

Brian Algeri bdasp at hotmail.com
Sat Aug 7 09:20:08 UTC 2004


Hi,

Just a small question that I have?
I hope the formating is not messed up.

***********************

in the below c code:

form = c_string_to_object(str5);
recset = cl_safe_eval(form,Cnil,Cnil);

The above code snip works:
str5 evaluates to "(cla:get-rec 1 cla::*person-tbl*)"
with 1 being whatever the record key is.
recset now contains a list of the record.

***********************

This does not work:

form = c_string_to_object("cla:get-rec");
recset = cl_funcall(3, form, MAKE_FIXNUM(rec),
                    c_string_to_object("cla::*person-tbl*");

Where rec is the record key.
I get the scrolling index 0 errors, when paused and scrolled to
the top it says that cla::*person-tbl* is not a hash-table, which
it is - works in the ecl shell. I also tried to export
cla::*person-tbl* and used the cla:*person-tbl format and this also
does not work. cla is the nickname for my lisp package.

***********************

I guess it doesn't matter as I can just use the cl_safe_eval but,
out of curiosity why does the cl_safe_eval work and the cl_funcall
does not for this particular instance.  I am using cl_funcall
at a later point in this function which works --see below code.

***********************

Reference code follows:

;;;; These work with the below c code

(defun get-rec (key hash)
  (gethash key hash))

(defun get-state-recs ()
  (let ((recset nil))
    (maphash #'(lambda (k v)
		 (push (list k v) recset))
	     *state-tbl*)
    recset))

// this works with the above lisp code
int GetContactRec(HWND hWnd, long rec)
{

  cl_object recset, rec2, hold, form, key;
  char str1[6];
  char str2[] = "(cla:get-rec ";
  char str3[] = " cla::*person-tbl*)";
  char str4[5];
  char str5[40];
  int x, index, state;
  HWND comboBox = GetDlgItem(hWnd,IDC_COMBOSTATE);
  const nstates = 50;

  // build string
  ltoa(rec, str4, 10);
  strcpy(str5, str2);
  strcat(str5, str4);
  strcat(str5, str3);

  form = c_string_to_object(str5);
  recset = cl_safe_eval(form,Cnil,Cnil);

  // set dialog edit controls
  hold = cl_cadr(recset);
  SetDlgItemText(hWnd, IDC_FNAME, hold->string.self);
  hold = cl_fourth(recset);
  SetDlgItemText(hWnd, IDC_LNAME, hold->string.self);
  hold = cl_sixth(recset);
  SetDlgItemText(hWnd, IDC_TITLE, hold->string.self);
  hold = cl_eighth(recset);
  SetDlgItemText(hWnd, IDC_DEPT, hold->string.self);
  hold = cl_tenth(recset);
  SetDlgItemText(hWnd, IDC_ADDR, hold->string.self);
  hold = cl_nth(MAKE_FIXNUM(11),recset);
  SetDlgItemText(hWnd, IDC_CITY, hold->string.self);
  hold = cl_nth(MAKE_FIXNUM(15),recset);
  ltoa(fixint(hold), str1, 10);
  SetDlgItemText(hWnd, IDC_ZIP, str1);
  hold = cl_nth(MAKE_FIXNUM(13),recset);
  state = fixint(hold);

  //*** organizations listbox code will go here

  //*** phone numbers listbox code will go here


  // fill state combo box
  form = c_string_to_object("cla:get-state-recs");
  recset = cl_funcall(1,form);

  // first record
  rec2 = cl_car(recset);
  hold = cl_cdr(recset);

  for (x = 0; x < nstates; x++)
  {
    key = cl_car(rec2);
    rec2 = cl_cadr(rec2);

    index =  SendMessage(comboBox, CB_ADDSTRING, 0,
			(LPARAM)(LPCTSTR)rec2->string.self);
    SendMessage(comboBox, CB_SETITEMDATA, index,
		(LPARAM)fixint(key));

    // next record
    rec2 = cl_car(hold);
    hold = cl_cdr(hold);

  }

  // set combo box to correct state or country
  for (x = 0; x < nstates; x++)
  {
    if (SendMessage(comboBox, CB_GETITEMDATA, x, 0) == state)
      SendMessage(comboBox, CB_SETCURSEL, x, 0);
  }

  return 0;
}


***********************

Thanks,
Brian Algeri

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
hthttp://messenger.msn.click-url.com/go/onm00200471ave/direct/01/





More information about the ecl-devel mailing list