[its-hackers] Muddle function to remove a node from a list.

rrs0 at earthlink.net rrs0 at earthlink.net
Wed Apr 14 03:20:50 CEST 2021


Hi Tim and everyone,
I am implementing  DROP used in the muddle package system and Also called by L-UNUSE.
For DROP I'm going to have to preform surgery on .OBLIST to remove the dropped package's oblist.
I may have been to ambitious about writing a general list node remover. I have now making a sallow 
Copy of the given list and returning a new list. I guess that at the end of DROP, I will do  the
dangerous and scary SETing of .OBLIST (not sure if ,OBLIST should be changed too) at the end of DROP.
L-UNUSE then removes the package name for the PACKAGE!- oblist and unSET's and REMOVEs the
atoms  from their oblist. Sofar I almost done with DROP. I coded FNDOBLIDX and   LRM. 

; "find the index needed by NTH of the package's oblist in .OBLIST."
<DEFINE FNDOBLIDX (PKN "OPT" (OBLS .OBLIST)
		      "AUX" (IDX 0) X Y Z )
	<REPEAT ((I 1)(LEN <LENGTH .OBLS>) OBL) 
		<SET OBL <NTH .OBLS .I>>
		<SET OBNAM <PNAME <GET .OBL OBLIST>>>
		<COND (<=? .PKN .OBNAM>
		       <SET IDX .I> <RETURN .I> )
		      (T <SET I <+ .I 1>> )>
		<AND <G? .I .LEN> <RETURN <SET IDX 0>> >
	>
	<COND (<0? .IDX> <SET IDX #FALSE(OBLIST-NOT-FOUND) >)>
	.IDX
 >


;" REMOVE THE NTH NODE IN A LIST. Doesn't MODIFIES THE ORGINAL LIST
  LIKE REST FOR N ==? 0 RETURN THE LIST"
<DEFINE LRM (L N "AUX" X Y Z (LST <LIST !.L>)"ACT" A)
	#DECL( (L LST VALUE) LIST (N) FIX)
	<COND (<==? .N 0> <RETURN <SET LST .LST> .A> )
	      (<==? .N 1> <RETURN <SET LST <REST .LST>> .A> )>
	     <PUTREST <REST .LST <- .N 2>>
		      <REST .LST <+ .N 0>>> >
	.LST>

  
;"not done with DROP yet."
<DEFINE DROP(PKN "AUX" NOBLS OOBLS N X Y Z) 
	#DECL((PKN) STRING (N) <OR FIX FALSE>
	      (NOBLS VALUE OOBLS)<OR <LIST [REST OBLIST]> FALSE> )
	<SET OOBLS .OBLIST>
	.........................
	 <SET N <FNDOBLIDX .PKN>>
	.........................
	<SET NOBLS <LRM .OOBLS N>
	....................
	<SET OBLIST .NOBLS>
>

Getting rid of the 1st node longer list without copying is hard. That may heave to one writer in the muddle assembler
And not sure what to do if someone has point to that node, most likely would have to set the moved node's link 
Point to 0. Not sure what else the would mess up!

	Rick
> On Apr 13, 2021, at 3:22 PM, Timothy Anderson <taa at alum.mit.edu> wrote:
> 
> What's the actual code for this? Semantics seems unclear to me: although you can mangle a multiple element list to remove any element as a side effect (seems less than tasteful, but that's another matter), what do you do with a singleton?
> Or are you modifying an atom's value, rather than the list itself?
>     -ta
> 
> Ceterum autem censeo Microsoftem esse delendam.
> 
> From: Eric Swenson <eric at swenson.org>
> Sent: Sunday, April 11, 2021 4:25:02 PM
> To: rrs0 at earthlink.net <rrs0 at earthlink.net>
> Cc: Lars Brinkhoff <lars at nocrew.org>; Its Hackers <its-hackers at its.victor.se>; ChrisXReeve at gmail.com <ChrisXReeve at gmail.com>; Timothy Anderson <taa at alum.mit.edu>
> Subject: Re: [its-hackers] Muddle function to remove a node from a list.
>  
> My opinion only and not necessarily based on any well-founded principles or precedents:
> 
> It should return the mutated list. The caller already has the node that was removed (having passed it as an argument), but in order to perform further operations on the mutated list, having your function return it allows callers to invoke functions on the result of calling your function — rather than having saved a reference to the before-mutated list in a local variable, and then having to perform tour side-effecting function, ignoring the result, and having to referenced the saved reference to the now-mutated list.
> 
> -- Eric
> 
> 
> > On Apr 11, 2021, at 11:53, rrs0 at earthlink.net wrote:
> > 
> > Hi Lars, and muddle hackers,
> > 
> > While working on the ITS Muddle Package System, I found a need for function that removes a
> > Node from .OBLIST. SO I wrote a general purpose node remover that modifies the original
> > List. My question is my function more useful if it returns the List or the  node it removed??
> > 
> >        Rick
> > 
> > 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://its.victor.se/pipermail/its-hackers_its.victor.se/attachments/20210413/226931d6/attachment-0001.html>


More information about the its-hackers mailing list