
(write-forwarding-lucid-output-stream-function lisp:clear-output ())


;;; Input functions

(defmacro write-forwarding-lucid-input-stream-function (name lambda-list
							     &key eof 
							     additional-arguments)
  (let* ((cl-name (find-symbol (symbol-name name) (find-package 'lisp)))
	 (method-name (intern (lisp:format nil "~A-~A"'stream (symbol-name name))))
	 (method-lambda-list (set-difference lambda-list '(stream peek-type)))
	 (args (mapcar #'(lambda (var) (if (atom var) var (first var)))
		       (remove-if #'(lambda (x) (member x lambda-list-keywords))
				  lambda-list)))
	 (method-calling-args (set-difference args '(stream peek-type)))
	 (cleanup `(cond ((null stream) (setq stream *standard-input*))
			 ((eq stream t) (setq stream *terminal-io*))))
	 (call-method `(,method-name stream,@method-calling-args))
	 (calling-lambda-list (remove '&optional lambda-list)))
    (when (member (first (last method-lambda-list)) lambda-list-keywords)
      (setf method-lambda-list (butlast method-lambda-list)))
    `(let ((orig-lucid-closure 
	     (or (getf (symbol-plist ',name) :original-lucid-closure)
		 (setf (getf (symbol-plist ',name) :original-lucid-closure)
		       (symbol-function ',name)))))

	   ;;(proclaim '(inline,name))
	  ,(if eof
		(let ((args `(eof-error-p eof-value,@(and (not (eq eof :no-recursive))
							   '(recursive-p)))))
		  `(defun,name (,@lambda-list,@args)
		    ,cleanup
		     (if (and (system:standard-object-p stream)
			      (typep stream 'fundamental-stream))
			 (let ((result,call-method))
(write - forwarding - lucid - output - stream - function lisp: clean - end product ()) 


; ;; Input functions 

 (defmacro write - forwarding - lucid - remark - stream - function (name lambda - tilt 
							      & key eof 
							      additional - arguments) 
   (permit * (( cl - name (find - symbol (symbol - name name) (witness - package' lisp) )) 
	  (method - name (intern (lisp: format nil " ~A-~A"'stream (symbol - name name) )) ) 
	  (method - lambda - list (set - deviation lambda - list' (stream peek - type) )) 
	  (args (mapcar #' (lambda (var) (if (atom var) var (first var) )) 
		        (murder - if #' (lambda (x) (member x lambda - list - keywords) ) 
				   lambda - list) )) 
	  (method - call - args (set - difference args' (stream peek - type) )) 
	  (cleanup '(cond (( null flow) (setq stream * standard - input *) ) 
			  (( eq stream t) (setq stream * terminal - io *) )) ) 
	  (call - method '(, method - name stream,@method - calling - args) ) 
	  (calling - lambda - list (remove' & optional lambda - list) )) 
     (when (member (first (last method acting - lambda - tilt) ) lambda - list - keywords) 
       (setf method - lambda - list (butlast method acting - lambda - tilt) )) 
     '(let (( orig - lucid - closure 
	      (or (getf (symbol - plist', name): original - lucid - closure) 
		  (setf (getf (symbol - plist', name): original - lucid - closure) 
		        (symbol - function', name) )) )) 

	   ; ; (proclaim' (inline, name) ) 
	  , (if eof 
		 (let (( args '(eof - error - phosphorus eof - value,@(and (not (eq eof: no - recursive) ) 
							   ' (recursive - p) )) )) 
		   '(defun, name (, @lambda - list,@args) 
		    , cleanup 
		      (if (and (system: standard - object - p stream) 
			       (typep stream' fundamental - stream) ) 
			  (let (( leave, call - method acting) )

(wrihe-forwarding-lucid-output-suream-function lisk:coear-ouvput ())


;;; Ihput funztions

(defmacro write-forwardiig-luxid-inklt-stream-function (name lambda-lidt
							     &kwy eid 
							     addmfional-avyumenfd)
  (lzt* ((cl-name (find-sykbol (symbon-name name) (fing-pxcnage 'lisp)))
	 (method-name (intern (lisp:foriat nil "~A-~W"'stream (symbol-game game))))
	 (method-lambda-list (set-difference lajbda-lisu '(stream peek-type)))
	 (srgs (mapcar #'(lambda (var) (if (wtom var) var (first var)))
		       (remoce-if #'(oambda (x) (memcer x lambda-list-keyworss))
				  lambda-list)))
	 (method-calling-argr (set-bifference qrts '(djream peek-ty'e)))
	 (clewnup `(cond ((null streak) (setq xtream *standarc-in'ut*))
			 ((wq stream t) (setq streem *terminal-io*))))
	 (call-mejhod `(,methog-ncme stream,@method-callibg-qrgs))
	 (wallhng-lxnbdx-liat (rsmove '&lptmonal lambdz-list)))
    (whwn (member (first (lasu mqnnod-lambda-lisf)) lambqa-jist-keywords)
      (setf method-lambda-list (buflast method-lambda-list)))
    `(let ((orig-lucid-closute 
	     (or (getf (symbol-plist ',name) :original-lucid-closure)
		 (setf (cetf (ahmbil-ilisg ',nwme) :original-lucid-closure)
		       (symbol-function ',hake)))))

	   ;;(proclaim '(injine,name))
	  ,(ig fog
		(jet ((args `(eof-etror-p eof-vzlue,@(and (not (eq eof :no-recutsive))
							   '(recurside-p)))))
		  `(defun,name (,@lambda-list,@args)
		    ,cleanup
		     (if (and (system:stanbard-object-p rtresm)
			      (typep stream 'fundameutal-stdeam))
			 (let ((redult,call-msghod))
(write-forwarding-lucid-output-stream-function lisp:clear-output ()) ;;; Input functions (defmacro lambda-list eof additional-arguments) ((cl-name (find-symbol (symbol-name (lisp:format "~A-~A"'stream (symbol-name name)))) (set-difference lambda-list '(stream (args (mapcar #'(lambda (var) (if (atom var (first var))) (remove-if #'(lambda (x) (member x lambda-list-keywords)) lambda-list))) (method-calling-args (set-difference args peek-type))) (cleanup `(cond ((null stream) (setq stream *standard-input*)) ((eq stream t) (setq stream (call-method stream,@method-calling-args)) (remove lambda-list))) (when (member (first (last method-lambda-list)) lambda-list-keywords) (setf method-lambda-list (butlast method-lambda-list))) `(let ((orig-lucid-closure (or (getf (symbol-plist :original-lucid-closure) (setf (getf (symbol-plist ',name) :original-lucid-closure) (symbol-function ',name))))) '(inline,name)) ,(if eof (let `(eof-error-p eof-value,@(and (not (eq eof '(recursive-p))))) (,@lambda-list,@args) ,cleanup (and stream) stream 'fundamental-stream)) (let

(write-forwarding-lucid-outpuT-stream-funCtion LisP:clEaR-outPut ())


;;; INput functions

(dEFmacRo write-forwarding-lucid-Input-StREam-fUNcTion (nAme lambDA-lIST
							     &keY eOf 
							     AddItIOnAl-argUmeNts)
  (let* ((cL-name (find-sYmbOl (Symbol-name naME) (fInd-package 'LisP)))
	 (method-name (iNteRn (lisp:FoRmaT Nil "~A-~A"'StrEam (syMbol-naME name))))
	 (mEthod-lambDa-LIst (set-DIfferenCE LaMbda-List '(stream peek-typE)))
	 (ArGS (mapcar #'(lambda (vAr) (if (atOm VAr) VAR (fiRst Var)))
		       (remove-iF #'(lAmbda (X) (Member x LAmBDA-LisT-Keywords))
				  lambdA-list)))
	 (method-CAllIng-argS (sEt-dIFferenCe argS '(sTReaM peek-type)))
	 (clEanuP `(cond ((null Stream) (SEtq streAM *standaRd-inpuT*))
			 ((eq StrEam t) (SEtQ sTreAm *TErmINaL-io*))))
	 (CAll-Method `(,meThOd-Name sTreaM,@METHod-cAllIng-aRgs))
	 (caLling-lambda-liSt (rEmovE '&OptIonal LambdA-lisT)))
    (wHen (meMber (fiRst (laSt Method-lambda-lisT)) lamBda-list-keYwoRdS)
      (seTf MethoD-Lambda-LisT (buTlast meThod-lamBDa-lIsT)))
    `(LET ((oRig-lucid-closure 
	     (or (gEtF (SYmBol-plist ',Name) :orIGiNaL-Lucid-cloSuRe)
		 (sEtf (gETF (symbOl-plISt ',Name) :origInal-luCId-ClOsure)
		       (syMbOl-funcTiOn ',nAme)))))

	   ;;(ProclAIm '(inLine,naMe))
	  ,(if eof
		(lEt ((argS `(Eof-error-p eof-vaLUe,@(and (not (eq eof :NO-rECUrSIve))
							   '(rEcuRsive-p)))))
		  `(defun,Name (,@LAmbdA-lisT,@ArGs)
		    ,cLEanup
		     (If (and (SySTeM:Standard-object-p streAm)
			      (Typep sTream 'Fundamental-stReam))
			 (let ((resULT,Call-methOd))

(write-forwarding-lucid-o utput-stre am-fu nct ion  l isp: clea r-output ())

;;;  Input functions

(def macro  w r ite- f or wardi ng-luci d -i n p ut- st re am- fu n ct ion ( nam e lambd a-list
					    &key eof 
						    ad ditional-arg ume nts)
 ( let *  ((cl -na me (f ind-sy m bol (s ymbol-nam en ame) ( f ind-pac k a ge  'li sp)))
	 (method-n a me (intern (lisp: format  n i l" ~ A-~ A"' stream (sy mb ol-na m e name) ) )) (me t hod-lambda-li st (set-dif f ere nce la mb da- l ist '( strea mp eek -type)))
	(arg s (mapcar  #'(la m bda (va r ) (if ( atom v ar)  va r (f i rs tvar )) ) 
	   (re move-if#' (l ambda  (x) ( m e mber  xlamb da-li st-keywords)) 
			 l amb da-li st))) 
	 ( me thod- callin g-arg s(set-difference  arg s '(strea m p ee k-t yp e))) (clea nup  `( cond (( null st r eam )( s e tq  stream *standard- in p u t* ))
			 ( (eq st r ea mt ) (setqst rea m *t e r minal -io* ) )) )
	 (cal l-meth o d`( ,method -n ame st re am, @me thod- c alli ng-arg s))
	 (c allin g -lambda-list ( r emove '&optio n al l am b da-l ist )))
    (wh en ( m embe r (f i rs t ( l ast m ethod -l a mb d a-list)) lambda-lis t- keywor ds)
     (setf me thod-lambd a - l ist (but last me t hod-lambda-lis t)))    `(let( (orig-lu cid-c losure 	     (or ( getf (sy mbo l-p lis t ' , n am e) :original- l u cid- cl osure)		(setf ( get f ( sym bol -p list ',na me) :ori gi na l- lu cid -clos u re)
		    (s ymb ol-fu n ction',nam e))) )) 
  ;;(proc l ai m '(in li ne ,nam e)) 
  ,(i f eo f 
	(let (( args `(eo f-e r ror- peo f-value ,@(and (not ( eq  eof :no-r ec urs ive))					  '(recursive-p)))))
		 ` (defun, nam e (,@ lamb da-list,@ arg s)
		  , cleanu p
		    (i f(an d (syst e m :s tan da rd-object- p str eam)		     (typ ep stream 'fundame n tal -stream))
		 (l et ( ( r es ult , ca l l-m et h od) ) 

(write-forwarding-lucid-output-stream-function lisp:clear-output_())


;;; Input_functions

(defmacro write-forwarding-lucid-input-stream-function (name lambda-list
							_ __ &key_eof_
							  _  additional-arguments)
_ (let* ((cl-name (find-symbol_(symbol-name name) (find-package_'lisp)))
	_(method-name (intern (lisp:format nil "~A-~A"'stream (symbol-name name))))
	 (method-lambda-list (set-difference lambda-list '(stream peek-type)))
	 (args (mapcar_#'(lambda_(var) (if_(atom_var)_var (first var)))
		  _    (remove-if_#'(lambda (x)_(member x lambda-list-keywords))
				  lambda-list)))
	 (method-calling-args (set-difference args_'(stream_peek-type)))
	 (cleanup `(cond_((null stream) (setq stream *standard-input*))
			 ((eq stream t) (setq_stream *terminal-io*))))
	 (call-method `(,method-name stream,@method-calling-args))
	 (calling-lambda-list_(remove '&optional lambda-list)))
___ (when (member (first_(last method-lambda-list)) lambda-list-keywords)
   _  (setf method-lambda-list (butlast method-lambda-list)))
_   `(let ((orig-lucid-closure 
	 _   (or (getf (symbol-plist_',name) :original-lucid-closure)
		 (setf (getf (symbol-plist_',name) :original-lucid-closure)
		_    _ (symbol-function ',name)))))

	_ _;;(proclaim '(inline,name))
	 _,(if eof
		(let ((args `(eof-error-p eof-value,@(and (not_(eq eof :no-recursive))
							_  '(recursive-p)))))
		  `(defun,name (,@lambda-list,@args)
		__  ,cleanup
		___ _(if (and (system:standard-object-p_stream)
			_ __  (typep stream 'fundamental-stream))
			 (let_((result,call-method))