Do we have explode and implode primitives in KCL?
Thanks.
--
* Dharmendra ····················@anucsd.anu.edu.AU-post: *
*Computer Science Department, ANU, GPO Box 4, Canberra ACT 2601, Australia *
*From down under | Live to study and not study to live *
******************************************************************************
In article <·················@kaffa> ·······@kaffa.anu.oz.au
(Dharmendra Sharma) writes:
>Do we have explode and implode primitives in KCL?
I don't use [A]KCL, but explode/implode are not part of Common LISP.
Following is some code from several years back to implement them in CL.
Feel free to do whatever you want with the code.
- Marty Hall
------------------------------------------------------
····@aplcen.apl.jhu.edu, ···········@jhunix.bitnet, ..uunet!aplcen!hall
Artificial Intelligence Lab, AAI Corp, PO Box 126, Hunt Valley, MD 21030
(setf (need-p 'disclaimer) NIL)
============================== CUT HERE ==============================
;;;======================================================================
;;;======================================================================
;;; Some utilities similar to those in earlier LISPs (eg Franz).
;;; 1986-1991 Marty Hall
;;;======================================================================
;;;======================================================================
;;;======================================================================
;;; Basically a "string" function that also handles numbers
(defun Into-String (Item)
(typecase Item
(string Item)
(symbol (string Item))
(t (princ-to-string Item))) )
;;;======================================================================
;;; Takes a character (#/a), a symbol ('A) or a 1-element string ("A") and
;;; returns a symbol (A). Also works on a 1-digit number (7).
(defun Read-from-Char (Character)
(read-from-string (Into-String Character)) )
;;;======================================================================
;;; (Explode 'foo-2) --> (F O O - 2), (Explode '123) --> (1 2 3)
;;; It is the possible presence of numbers that forces "Into-String" instead
;;; of "symbol-name"
(defun Explode (Symbol)
(map 'list #'Read-from-Char (Into-String Symbol)) )
;;;======================================================================
;;; (Implode '(A B C D 2)) --> ABCD2, (Implode '(A TEST)) --> ATEST
;;; (set (Implode '(F O O - 3)) 9) --> 9, FOO-3 --> 9
(defun Implode (List)
(read-from-string (apply #'concatenate 'string
(mapcar #'Into-String List))) )
;;;======================================================================