Equivalent of READ lisp function in .net?

Equivalent of READ lisp function in .net?

JamesMaeding
Advisor Advisor
1,783 Views
6 Replies
Message 1 of 7

Equivalent of READ lisp function in .net?

JamesMaeding
Advisor
Advisor

So I have old data files that have lisp lists represented as strings.

I could write my own lisp parser, but wanted to try to get acad to read them for me into a resultbuffer.

 

I have the pinvoked acedEvaluateLisp and was trying to send it something like:

string evalthis = "(read \"" + stringtoread + "\")";

 

but that string does not quite work, as I do not want the \" before and after the stringtoread, I just want "

But the code must have the \ to make the quotes part of the string.

I think I need to use the READ function from lisp if possible, as wrapping the string with read is not working.

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
1,784 Views
6 Replies
Replies (6)
Message 2 of 7

owenwengerd
Advisor
Advisor

Did you perhaps also want to evaluate the string?

 

string evalthis = "(eval (read \"" + stringtoread + "\"))";

--
Owen Wengerd
ManuSoft
0 Likes
Message 3 of 7

JamesMaeding
Advisor
Advisor

no, as the items are a lisp list of data, not variable names.

That trick of using eval to allow passing functions variables "byreference" is slick, where you pass in the var name as a string, and it gets eval's to be a variable, just not what I'm doing here.

 

My lisp function I want to do in .net looks like:

(DEFUN FILE-TO-LST-READ (FILE-NAME / INDEX RESULT DATA-FILE RLINE)
  (SETQ RESULT nil)
  (SETQ DATA-FILE (OPEN FILE-NAME "r"))
  (WHILE (SETQ RLINE (READ-LINE DATA-FILE))
    (IF (AND (/= RLINE NIL)(/= RLINE "")(/= (SUBSTR RLINE 1 1) "'"))
      (SETQ RESULT (CONS (READ RLINE) RESULT))
    )
  )
  (close DATA-FILE)
  (SETQ RESULT (REVERSE RESULT))
  RESULT
)

 

so I am just taking a text file containging a lisp list and converting to a list (resultbuffer).

example text for a horizontal alignment text file:

 

(("NAME" . "+Robert Street")("DESCRIPTION" . "xfghfdghf")("PATH" . "C:\Users\james\Desktop\Test Aligns")("TYPE" . "BASIC")("USER"  . "james")("DATE" . "01/08/15 1:24:28 PM")("STSTATION" . 789.9491148719630)("LENGTH" . 2208.169868062913)("STAEQS" . "None"))
(("START" . (-751.9091561265257 186.7627361809725 0.0))("END" . (-378.9933107305748 357.2781332772743 0.0)))
(("CENTER" . (69.74878846892860 -624.1173426586973 0.0))("RADIUS" . 1079.123047562959)("STANG" . 1.291887827092442)("ENDANG" . 1.999662145471057)("DIR" . "CW"))
(("CENTER" . (778.0616444626744 1849.275744619477 0.0))("RADIUS" . 1493.692621341728)("STANG" . 4.433480480682234)("ENDANG" . 5.125954547113812)("DIR" . "CCW"))

 

I use xml usually, this is just an old way of storing things for very fast "read in" later. Seems faster than parsing an xml in lisp so far, but maybe .net parses faster...


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 4 of 7

JamesMaeding
Advisor
Advisor

btw, the read function does work on simple stuff in .net, like:

AcadEvalLisp("(read \"(1 2 3)\")");

 

but it does not work with anything that is a string, like:

AcadEvalLisp("(read \"(\"a\" \"b\" 1 2 3)\")");

 

so maybe its not the \" at start and end, but the quotes in the middle for the string values.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 5 of 7

JamesMaeding
Advisor
Advisor

oh, I see. My .net function does the eval, I just want the read.

I looked through the pinvoke export lists, did not see anything like lisp read function so far....


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 6 of 7

owenwengerd
Advisor
Advisor

I think it would be helpful if you post specially crafted sample code that demonstrates the problem.

--
Owen Wengerd
ManuSoft
0 Likes
Message 7 of 7

JamesMaeding
Advisor
Advisor

I would if I thought there was an answer, but I have a feeling there is no "serialized lisp list to result buffer" function in .net via pinvoke. I'd love to be wrong on that.

 

 I know I could make a lisp function in lisp to do the read, and call that from .net, but the return journey is nasty as I never send complex lists to .net in any form other than xml serialized lists due to how .net reformats certain resultbuffer items incorrectly. So I have to serialize on lisp end, then unravel the xml string on .net end which is more overhead than just making parsing in .net to begin with.

 

I did write my own last night, and thought it was too slow at first during debug. Then tried release version and its super fast. So I'm not really worried about the pivoke read function as much now...


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes