Xref: utzoo comp.os.vms:5894 comp.lang.pascal:856 Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!ncar!boulder!tramp!sanford From: sanford@tramp.Colorado.EDU (SANFORD STEPHEN LEE) Newsgroups: comp.os.vms,comp.lang.pascal Subject: Re: Quoted string parameters in VAX Pascal? Message-ID: <5787@sigi.Colorado.EDU> Date: 2 May 88 22:02:38 GMT References: Sender: news@sigi.Colorado.EDU Reply-To: sanford@tramp.Colorado.EDU (Steve Sanford Jr.) Organization: University of Colorado, Boulder Lines: 71 Summary: "String" Records In his provocative and exciting article, elkins@elbereth.rutgers.edu (George Elkins) writes: > >Is there a way in VAX Pascal to define a procedure that will take >a variable length quoted string as a parameter? What I would like >to do is imitate the variable length quoted string parameter behavior >of the WRITE and WRITELN procedures, although this is not possible >for user-written procedures in STANDARD Pascal. I want the quoted >string parameter to be within the argument list itself, as in the >WRITELN procedure. I am trying to avoid assigning the string to an >arbitrarily long fixed-length packed array and passing the Pascal >identifier for the array and the integer length of the string. > >Example of what I want to do: > > foo('This is a string of any length'); {User-written procedure foo} > . . . > >George Elkins One possibility is to define your "string" as follows: ---------------------------------------------------------- type stringptr: ^newstring; newstring: record ch: char; next: stringptr end; var x: newstring; ---------------------------------------------------------- Then, work with the string using procedures. For example: ---------------------------------------------------------- function length (x: newstring): integer; begin if (x = nil) then length := 0 else length := 1 + length (newstring^.next) end; procedure readin (var x: newstring); var temp: newstring; ch: char; begin x := nil; read (ch); if (not (eoln)) then begin new (x); x^.ch := ch; x^.next := nil; temp := x; read (ch); while (not (eoln)) do begin new (temp^.next); temp := temp^.next; temp^.ch := ch; temp^.next := nil; read (ch) end; end; end; (* readin *) --------------------------------------------------------------------- {These procedures could probably be improved upon; the checks for (eoln) might be improperly placed. Give me more time, I'll give you correct code. } Obviously, the data structure isn't a static "string", but a linked list of characters. The procedures are a bit more complicated, but it gives you the "variability" you desired; strings can be as short or as long as you want, and "foo (x)" will work with them regardless. Good luck. If you want, e-mail me a request for more (correct) code; I'm just a poor student, who will do ANYTHING to avoid studying for finals. **************************************** ___ * If you set your mind to it, you can do * /__ teve * do anything. Except ski through a * ___/anford Jr. * revolving door. * ***************** - some optimist ******