Hi im making a program where you sort through different homeopathic remedies, one of the functions i do is a general search where a user will write a word or part of it and the program will reply with all the partial matches
(PRINTKEY 'FIEBER PLANTS);--> EXAMPLE
;CORDYCEPS IST FIEBERSENKEND
;BAIKAL-HELMKRAUT IST FIEBERSENKEND
;BAIKAL-HELMKRAUT VERRINGERT FIEBER
;EBOLAFIEBER WIRD DURCH EINEN KRANKHEIT VERSURSACHT
...
Can anyone help me so it doesn't look like this anymore
GINGER IS ANALGETIKUM
HOUTTUYNIA IS ANALGETIKUM
but instead group the plants like this.
ANALGETIKUM is a property of INGWER, HOUTTUYNIA
(DEFPARAMETER PLANTS
'(
((NAME TRAGANT ASTRALAGUS )(BAKTERIEN )(VIREN HERPES-SIMPLEX BUNYAVIREN PORCINE-PARVOVIRUS PUNTA-TORO-VIREN CYTOMEGALOVIRUS ADENOVIREN COXSACKIE-VIRUS )(INFEKTIONSKRANKHEITEN HEPATITIS-B STAUPE JAPANISCHE-ENZEPHALITIS INFLUENZA INFEKTIOESE-BURSITIS-DER-HUEHNER )(EIGENSCHAFTEN ADAPTOGEN ANTIBAKTERIELL ANTIHEPATOTOXISCH ANTIVIRAL KARDIOPROTEKTIV DIURETIKUM BLUTDRUCKSENKEND IMMUNSTAERKER )(VERBESSERN BLUTKREISLAUF IMMUNFUNKTION )(VERRINGERN VIRALEN-INFEKTIONEN ))
((NAME CORDYCEPS CORDYCEPS )(BAKTERIEN CANDIDA-ALBICANS BACILLUS-SUBTILIS ENTEROCOCCUS-FAECALIS STAPHYLOCOCCUS-AUREUS CLOSTRIDIEN PLASMODIUM TUBERKELBAZILLUS )(VIREN HIV HERPES-SIMPLEX )(INFEKTIONSKRANKHEITEN HEPATITIS-B KREBS INFLUENZA NEWCASTLE-INFEKTION )(EIGENSCHAFTEN ANTIVIRAL ANTIASTHMATISCH ANTIBAKTERIELL ANTIKONVULSIVUM ENTZUENDUNGSHEMMEND ANTIMIKROBIELL ANTIOXIDATIONS FIEBERSENKEND ANTITUMORMITTEL ANTITUSSIVUM BRONCHIALREGULATOR KARDIOTONISCH SCHLEIMLOESEND HEPATOPROTEKTIV HYPOGLYKAEMISCH HYPOLIPIDAEMISCH IMMUNMODULATOR INSEKTIZID MITOCHONDRIEN-ADAPTOGEN NERVENBERUHIGUNG NEUROPROTEKTIV NIERENSCHUETZEND SCHLAFREGULIEREND STEROIDBILDEND )(VERRINGERN KONVULSIONEN ASTHMA VIRALEN-INFEKTIONEN ENTZUENDUNGEN FATIGUE HUSTEN SCHWINDELGEFUEHLE NYKTURIE )(VERBESSERN LIBIDO ))
((NAME BAIKAL-HELMKRAUT SCUTELLARIA-BAICALENSIS )(BAKTERIEN )(VIREN HRSV HIV HERPES-SIMPLEX PRRS-VIREN POLIOVIRUS PARAINFLUENZAVIRUS MOSAIKVIRUS EPSTEIN-BARR-VIRUS COXSACKIE-VIRUS ENTEROBAKTERIOPHAGE-MS2 ADENOVIREN )(INFEKTIONSKRANKHEITEN HEPATITIS-A HEPATITIS-B HEPATITIS-C SENDAIVIRUS-INFEKTION SARS-COV PARAINFLUENZA MASERN LEUKAEMIE INFEKTIOESE-BRONCHITIS STOMATITIS-VESICULARIS INFLUENZA )(EIGENSCHAFTEN ANODYNE ANTIANAPHYLAKTISCH ANTIANGIOGENE ANTIBAKTERIELL ANTIVIRAL ANTICHOLESTEROLEMIKUM ANTIKONVULSIVUM ANTIDIARRHOISCH ANTIDYSENTERISCH ANTIMYKOTISCH ANTIHYPERTENSIV ENTZUENDUNGSHEMMEND ANTIMETASTISCH ANTIOXIDATIONS ANTISPASMODISCH ANTITUMORMITTEL ADSTRINGIEREND CHOLAGOGUM DIURETIKUM SCHLEIMLOESEND FIEBERSENKEND BLUTSTILLEND HEPATOPROTEKTIV SEDATIVUM NERVENSTAERKEND NEUROPROTEKTIV )(VERBESSERN GEHIRNFUNKTION )(VERRINGERN VIRALEN-INFEKTIONEN FIEBER DURCHFALL DYSENTERIE KRAMPFANFALL KONVULSIONEN INSOMNIE ))
((NAME HOLUNDER SAMBUCUS )(BAKTERIEN )(VIREN HRSV HIV HERPES-SIMPLEX FELINE-CALICIVIRUS MURINE-NOROVIRUS ROTAVIRUS TABAKMOSAIKVIRUS CYTOMEGALOVIRUS JUNIN-VIRUS RHINOVIREN PORCINE-EPIDEMIC-DIARRHEA-VIRUS PORCINE-CIRCOVIRUS EPSTEIN-BARR-VIRUS ADENOVIREN POLIOVIRUS ENTEROVIREN COXSACKIE-VIRUS )(INFEKTIONSKRANKHEITEN HEPATITIS-B HEPATITIS-C HEPATITIS-E EBOLAFIEBER VOGELPOCKEN DENGUE SARS-COV STOMATITIS-VESICULARIS WEST-NILE-ENZEPHALITIS JAPANISCHE-ENZEPHALITIS STAUPE CHIKUNGUNYAFIEBER INFLUENZA )(EIGENSCHAFTEN ANTIVIRAL ANTIBAKTERIELL ANTIMYKOTISCH ANALGETISCH ENTZUENDUNGSHEMMEND ANTINOZIZEPTIV KREBSHEMMEND ANTIANGIOGEN ANTITERATOGEN SCHWEISSTREIBEND DIURETIKUM PROSTAGLANDIN-SYNTHESE-HEMMEND FIEBERSENKEND ANTIOXIDATIONS IMMUNSTIMULIEREND )(VERRINGERN FIEBER SCHMERZ ENTZUENDUNGEN SCHWELLUNGEN VIRALEN-INFEKTIONEN )(VERBESSERN SCHWITZEN IMMUNFUNKTION ERBRECHEN LEBERSCHUTZ ))
((NAME INGWER ZINGIBER-OFFICINALE )(BAKTERIEN )(VIREN HIV HERPES-SIMPLEX MOSAIKVIRUS POLIOVIRUS VACCINIAVIRUS EPSTEIN-BARR-VIRUS CYTOMEGALOVIRUS RHINOVIREN ENTEROVIREN )(INFEKTIONSKRANKHEITEN HEPATITIS-B HEPATITIS-C NEWCASTLE-INFEKTION WINDPOCKEN MASERN GELBFIEBER INFLUENZA ERKAELTUNG )(EIGENSCHAFTEN ANTIVIRAL ANALGETIKUM ANTHELMINTHIKUM ANTIARTHRITISCH ANTIBAKTERIELL ANTIDIARRHOISCH ANTIEMETIKUM ANTIMYKOTISCH ENTZUENDUNGSHEMMEND KRAMPFLOESEND ANTITUSSIVUM KARMINATIVUM KREISLAUFSTIMULANS SCHWEISSTREIBEND ELASTASE-HEMMER BLUTDRUCKSENKEND IMMUNSTAERKER SYNERGIST )(VERBESSERN SCHWITZEN IMMUNFUNKTION BLUTKREISLAUF )(VERRINGERN VIRALEN-INFEKTIONEN NASENSCHLEIMHAUT DURCHFALL MOMADE KRAMPFANFALL FIEBER SCHUETTELFROS ENTZUENDUNGEN HUSTEN ANGSTZUSTAENDE SCHMERZ ERKAELTUNG MIGRAENE KOPFSCHMERZEN ))
((NAME HOUTTUYNIA HOUTTUYNIA-CORDATA )(BAKTERIEN STREPTOCOCCUS-PNEUMONIAE-SEROTYP-2 )(VIREN HIV HERPES-SIMPLEX PED-VIRUS CYTOMEGALOVIRUS ENTERIC-CYTOPATHIC-HUMAN-ORPHAN ENTEROVIREN )(INFEKTIONSKRANKHEITEN INFEKTIOESE-BRONCHITIS INFLUENZA SARS-COV DENGUE )(EIGENSCHAFTEN ANTIVIRAL ANALGETIKUM ANTHELMINTHIKUM ANTIBAKTERIELL ANTIKREBS ANTIMYKOTISCH ENTZUENDUNGSHEMMEND ANTILEUKAEMISCH ANTIMIKROBIELL ANTIOXIDATIONS ANTITUSSIVUM ADSTRINGIEREND DIURETIKUM ENTSCHLACKEND EMMENAGOGUM FIEBERSENKEND BLUTSTILLEND HYPOGLYKAEMISCH IMMUNMODULATORISCH LARVAZIDUM ABFUEHRMITTEL AUGENHEILKUNDE )(VERRINGERN VIRALEN-INFEKTIONEN HARNWEGE-INFEKTIONEN NIEREN-INFEKTIONEN GENITALBEREICH-INFEKTIONEN DYSENTERIE DURCHFALL AUGES-INFEKTIONEN HAUT-INFEKTIONEN ))
((NAME WAID ISATIS )(BAKTERIEN )(VIREN HRSV HERPES-SIMPLEX PRRS-VIREN AUJESZKY-VIRUS CYTOMEGALOVIRUS EPSTEIN-BARR-VIRUS COXSACKIE-VIRUS ADENOVIREN )(INFEKTIONSKRANKHEITEN HEPATITIS-B GUERTELROSE NEWCASTLE-INFEKTION HFRS INFEKTIOESE-BRONCHITIS MASERN MUMPS WINDPOCKEN INFLUENZA SARS-COV ROETELN LEUKAEMIE )(EIGENSCHAFTEN ANTIVIRAL ANTIENTZUENDLICH FIEBERSENKEND ANTINOZIZEPTIV ANTIALLERGISCH TYROSINASE-HEMMER ANTIOXIDATIONS ANTIMYKOTISCH ANTIBAKTERIELL ANTIPARASITAER ANTILEUKAEMISCH ANTITUMOR UREASE-HEMMER SERIN-PROTEASE-HEMMSTOFF HEMMSTOFF-DER-BUTYRYCHOLINESTERASE LIPOXYGENASE-HEMMER ANTIENDOTOXIN DIOXIN-ANTAGONIST )(VERRINGERN VIRALEN-INFEKTIONEN )(VERBESSERN BLUTKREISLAUF ))
((NAME SUESSHOLZ GLYCYRRHIZA-GLABRA )(BAKTERIEN )(VIREN HRSV HIV HERPES-SIMPLEX CHANDIPURAVIREN AUJESZKY-VIRUS MURINE-RETROVIRUS PRRS-VIREN EPSTEIN-BARR-VIRUS POLIOVIRUS CYTOMEGALOVIRUS VACCINIAVIRUS ENTEROVIREN ROTAVIRUS ADENOVIREN COXSACKIE-VIRUS )(INFEKTIONSKRANKHEITEN HEPATITIS-A HEPATITIS-B HEPATITIS-C HEPATITIS-D HEPATITIS-E MASERN STOMATITIS-VESICULARIS NEWCASTLE-INFEKTION INFEKTIOESE-BRONCHITIS INFLUENZA SARS-COV HRSV PARAINFLUENZA JAPANISCHE-ENZEPHALITIS TICK-BORNE-ENCEPHALITIS WEST-NILE-ENZEPHALITIS BOVINE-IMMUNODEFICIENCY WINDPOCKEN GELBFIEBER DENGUE PNEUMONIE )(EIGENSCHAFTEN ANTIVIRAL NEBENNIERENRINDE-STIMULANS NEBENNIERE-TONIKUM SCHMERZSTILLEND ANTIBAKTERIELL KREBSHEMMEND ANTITUMORMITTEL ANTIHAEMOLYTISCH ANTIHYPERGLYKAEMISCH ENTZUENDUNGSHEMMEND ANTIOXIDATIONS KRAMPFLOESEND ANTISTRESSIVUM ANTITUSSIVUM GEGEN-MAGENGESCHWUERE KARDIOPROTEKTIV ABFUEHRMITTEL OESTROGENE SCHLEIMLOESEND HEMMSTOFF-DER-MAGENSEKRETION HEPATOPROTEKTIV IMMUNSTIMULIEREND ABFUEHRMITTEL SCHLEIMHAUTSCHUETZEND STRAHLENSCHUTZ MUSKELENTSPANNER STIMULANS-BAUCHSPEICHELDRUESE SYNERGIST STIMULANS-THYMUSDRUESE TYROSINASE-HEMMER XANTHIN-OXIDASE-HEMMER )(VERRINGERN SCHMERZ MUND-BAKTERIELLEN-INFEKTIONEN VIRALEN-INFEKTIONEN KRAMPFANFALL GESCHWUERBILDUNG )(VERBESSERN IMMUNFUNKTION ))
((NAME LOMATIUM LOMATIUM )(BAKTERIEN SHIGELLA )(VIREN HIV EPSTEIN-BARR-VIRUS CYTOMEGALOVIRUS )(INFEKTIONSKRANKHEITEN BAKTERIELLE-INFEKTIONEN INFLUENZA SARS-COV VIRAL-ENCEPHALITIS PNEUMONIE )(EIGENSCHAFTEN SCHMERZSTILLEND ANTIBAKTERIELL ANTIMYKOTISCH ANTIMIKROBIELL ANTISEPTISCH KRAMPFLOESEND ANTIVIRAL SCHLEIMLOESEND SCHLEIMHAUT-TONIKUM )(VERRINGERN KRAMPFANFALL SCHMERZ VIRALEN-INFEKTIONEN BAKTERIELLEN-INFEKTIONEN ))
((NAME WASSERDOST EUPATORIUM-PERFOLIATUM )(BAKTERIEN )(VIREN )(INFEKTIONSKRANKHEITEN INFLUENZA MALARIA DENGUE )(EIGENSCHAFTEN SCHMERZSTILLEND ANTIBAKTERIELL ENTZUENDUNGSHEMMEND ZYTOTOXISCH SCHWEISSTREIBEND BRECHMITTEL FIEBERSENKEND BITTER-DEN-MAGEN IMMUNSTIMULIEREND SCHLEIMHAUT-TONIKUM BLUTSTILLEND GLATTER-MUSKEL-ENTSPANNEND )(VERRINGERN VIRALEN-INFEKTIONEN FIEBER SCHMERZ )(VERBESSERN SCHLEIMHAUT BLUTKREISLAUF SCHWITZEN ))
((NAME SAECKELBLUME CEANOTHUS-AMERICANUS )(BAKTERIEN )(VIREN )(INFEKTIONSKRANKHEITEN INFLUENZA)(EIGENSCHAFTEN LYMPHSYSTEMS-STIMULANS LYMPHSYSTEM-TONIKUM BLUTGERINNUNGSMITTEL )(VERRINGERN ENTZUENDUNGEN )(VERBESSERN LYMPHSYSTEMS BLUTKREISLAUF ))
((NAME ROSENWURZ RHODIOLA-ROSEA )(BAKTERIEN STAPHYLOCOCCUS-AUREUS BACILLUS-SUBTILIS TUBERKELBAZILLUS E-COLI )(VIREN COXSACKIE-VIRUS ENTEROVIREN )(INFEKTIONSKRANKHEITEN HEPATITIS-C JAPANISCHE-ENZEPHALITIS INFLUENZA )(EIGENSCHAFTEN ADAPTOGEN NEBENNIEREPROTEKTIV ANTI-KREBS ANTIDEPRESSIVUM GEGEN-MUEDIGKEIT ANTIOXIDATIONS ANTISTRESSIVUM KARDIOTONISCH ENDOKRINES-TONIKUM ERGOGEN HIPPOCAMPUS-SCHUTZMITTEL HIPPOCAMPUS-TONIKUM HYPOXIE-ANTAGONIST IMMUNSTAERKER MITOCHONDRIEN-STAERKEN MUSKELN-STIMULANS NERVENSYSTEMS-TONIKUM NERVENPROTEKTIV SYNERGIST )(VERRINGERN STRESS DEPRESSION FATIGUE ERSCHOEPFUNG GEHIRNNEBEL )(VERBESSERN MITOCHONDRIEN MUSKELN NERVENSYSTEMS ENDOKRINES IMMUNFUNKTION ))
))
;FUNCTION PRINTKEY
;ARRANGES THE INFORMATION NEEDED TO SEARCH FOR THE KEYWORD
;#PARAM KEYWORD: {STRING}, SEARCHED KEYWORD
;#PARAM LIS: {LIST}, LIST WITH ALL INFORMATION ABOUT THE PLANTS, INFECTIOUS DISEASES, PROPERTIES AND THERAPY TARGETS.
;#PARAM PLANT: {STRING}, NAME OF THE NOW ACTIVE PLANT.
(DEFUN PRINTKEY(KEYWORD LIS)
(LET*((PLANT (SECOND (ASSOC 'NAME (CAR LIS)))))
(COND ((NULL LIS))
(T (PRINTKEY-HELPER KEYWORD (CDR (ASSOC 'NAME (CAR LIS))) 'NAME PLANT)
(PRINTKEY-HELPER KEYWORD (CDR (ASSOC 'VIREN (CAR LIS)))) 'VIREN PLANT)
(PRINTKEY-HELPER KEYWORD (CDR (ASSOC 'BACTERIA (CAR LIS))) 'BACTERIA PLANT)
(PRINTKEY-HELPER KEYWORD (CDR (ASSOC 'INFECTIOUS DISEASES (CAR LIS))) 'INFECTIOUS DISEASES PLANT)
(PRINTKEY-HELPER KEYWORD (CDR (ASSOC 'PROPERTIES (CAR LIS))) 'PROPERTIES PLANT)
(PRINTKEY-HELPER KEYWORD (CDR (ASSOC 'REDUCE (CAR LIS))) 'DECREASE PLANT)
(PRINTKEY-HELPER KEYWORD (CDR (ASSOC 'IMPROVE (CAR LIS)))) 'IMPROVE PLANT)
(PRINTKEY KEYWORD (CDR LIS)))
)))
;FUNCTION PRINTKEY-HELPER
;SEARCHES FOR KEYWORD IN DATABASE AND PRINTS ALL PARTIAL MATCHES
;#PARAM KEYWORD: {STRING}, SEARCHED KEYWORD
;#PARAM LIS: {LIST}, LIST WITH ALL INFORMATION ABOUT THE PLANTS, INFECTIOUS DISEASES, PROPERTIES AND THERAPY TARGETS.
;#PARAM TYPE: {STRING}, NAME OF THE SEARCHED TYPE ('REDUCE, 'IMPROVE, 'PROPERTIES, 'NAME OR 'VIRUSES).
;#PARAM PLANT: {STRING}, NAME OF THE NOW ACTIVE PLANT.
(DEFUN PRINTKEY-HELPER(KEYWORD LIS TYPE PLANT)
(LET*((FOUND (SEARCH (STRING KEYWORD)(STRING (CAR LIS)) :TEST 'CHAR=))
(COND((NULL LIS))
((EQUAL KEYWORD 'HP)(START))
((AND (EQL TYPE 'NAME)(NOT (NULL FOUND)))(FORMAT T "~%~A IS AN ANTIBACTERIAL AND ANTIVIRAL PLANT WITH ANTIOXIDANT PROPERTIES."(CAR LIS))(PRINTKEY-HELPER KEYWORD (CDR LIS) TYPE PLANT))
((AND (EQL TYPE 'VIRUSES)(NOT (NULL FOUND)))(FORMAT T "~%~A IS CAUSED BY A VIRUS" (CAR LIS))(PRINTKEY-HELPER KEYWORD (CDR LIS) TYPE PLANT))
((AND (EQL TYPE 'INFECTIOUS DISEASES)(NOT (NULL FOUND)))(FORMAT T "~%~A IS CAUSED BY A DISEASE" (CAR LIS))(PRINTKEY-HELPER KEYWORD (CDR LIS) TYPE PLANT))
((AND (EQL TYPE 'BACTERIA)(NOT (NULL FOUND)))(FORMAT T "~%~A IS CAUSED BY A BACTERIA" (CAR LIS))(PRINTKEY-HELPER KEYWORD (CDR LIS) TYPE PLANT))
((AND (EQL TYPE 'PROPERTIES)(NOT (NULL FOUND)))(FORMAT T "~%~A IS ~A" PLANT (CAR LIS))(PRINTKEY-HELPER KEYWORD (CDR LIS) TYPE PLANT))
((AND (EQL TYPE 'DECREASE)(NOT (NULL FOUND)))(FORMAT T "~%~A DECREASES ~A" PLANT (CAR LIS))(PRINTKEY-HELPER KEYWORD (CDR LIS) TYPE PLANT))
((AND (EQL TYPE 'IMPROVE)(NOT (NULL FOUND)))(FORMAT T "~%~A IMPROVES ~A" PLANT (CAR LIS))(PRINTKEY-HELPER KEYWORD (CDR LIS) TYPE PLANT))
(T (PRINTKEY-HELPER KEYWORD (CDR LIS) TYPE PLANT))
)))
i accept ideas of how to do it
in PRINTKEY-HELPER i can use this
(FORMAT T "~A is a property of ~{~a~^, ~}.~%"(CAR LIS) (APPLY #'APPEND (MAPCAR (LAMBDA (ROW)(IF (FIND (CAR LIS) (CDR (ASSOC 'EIGENSCHAFTEN ROW))) (LIST(SECOND (ASSOC 'NAME ROW))))) PLANTS)))
but if when the word comes again the string will be repeated
Here is a what a somewhat more more tidy printkey-helper might look like, though I have not tested the code. I fixed the unbalanced parenthesis in the let* form.
(defun printkey-helper (keyword lis type plant)
(let* ((name (car lis)) ;; get name as local var to avoid repeating (car lis)
(found (search (string keyword) (string name) :test 'char=)))
(if found
(cond
((eq keyword 'hp) (start)) ;; what is this? Not mentioned in comment.
(t (case type
(name (format t "~%~a is an antibacterial and antiviral plant with antioxidant properties." name))
(viruses (format t "~%~a is caused by a virus" name))
(infectious (format t "~%~a is caused by a disease" name))
(bacteria (format t "~%~a is caused by a bacteria" name))
(properties (format t "~%~a is ~a" plant name))
(decrease (format t "~%~a decreases ~a" plant name))
(improve (format t "~%~a improves ~a" plant name)))
;; tail recurse in one place
(printkey-helper keyword (cdr lis) type plant))))))
I also removed the article "a" from "a bacteria" becuase the word is a plural of "bacterium". A bacterial disease is caused by a bacterium, or by multiple bacteria.
All that written and said, the way the search task is divided between printkey and printkey-helper isn't very good.
Why wouldn't you just loop through the plants in a single loop, picking out the matching ones, and then loop through the properties, printing all of the known ones with a descriptive text.
A helper function could be used to do the formatting of a property like infectious to the textual message.
(defun print-recognized-property (type plant-name)
(case type
(name (format t "~%~a is an antibacterial and antiviral plant with antioxidant properties." name)
;; ... etc
))
Then if we have a descriptor of a given plant, we can do something along these lines:
(loop for ((name-sym common-name latin-name) . properties) in plants
do (loop for (type . info) in properties
do (print-recognized-property type common-name)))
Related
I have this code below. It exports the selected polylines lenght to a CSV but it does not give it a name so i cant make a difference between two(or more) types of polyline.
My question is how to modify this code in order to be able to export the lenghts with the name of the linetype.
For example: I loaded ZIGZAG and TRACKS linetype, next I run my function and select all of the drawn polylines and I want to see in my CSV that which linetype is how long by name.
(defun c:Polyline_számoló (/ s i e l fn)
(if (and(setq s (ssget '((0 . "LWPOLYLINE"))))
(setq fn (getfiled "Create Output File" "" "csv" 1)))
(progn
(setq s (_SortSSByXValue s))
(setq i (sslength s))
(while (setq e(ssname s (setq i (1- i))))
(setq l (cons (vla-get-length (vlax-ename->vla-object e)) l))
(ssdel e s)
)
)
)
(setq l (list (cd:CON_All2Str l nil)))
(if (LM:WriteCSV l fn)
(startapp "explorer" fn)
)
(princ)
)
(defun cd:CON_All2Str (Lst Mode)
(mapcar
(function
(lambda (%)
(if Mode
(vl-prin1-to-string %)
(vl-princ-to-string %)
)
)
)
Lst
)
)
(defun _SortSSByXValue (ss / lst i e add)
(if (eq (type ss) 'PICKSET)
(progn
(repeat (setq i (sslength ss))
(setq lst (cons (cons (setq e (ssname ss (setq i (1- i))))
(cadr (assoc 10 (entget e)))
)
lst
)
)
)
(setq add (ssadd))
(foreach e (vl-sort lst (function (lambda (a b) (< (cdr a) (cdr b))))) (ssadd (car e) add))
(if (> (sslength add) 0)
add
)
)
)
)
(defun LM:writecsv ( lst csv / des sep )
(if (setq des (open csv "w"))
(progn
(setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList")) (",")))
(foreach row lst (write-line (LM:lst->csv row sep) des))
(close des)
t
)
)
)
(defun LM:lst->csv ( lst sep )
(if (cdr lst)
(strcat (LM:csv-addquotes (car lst) sep) sep (LM:lst->csv (cdr lst) sep))
(LM:csv-addquotes (car lst) sep)
)
)
(defun LM:csv-addquotes ( str sep / pos )
(cond
( (wcmatch str (strcat "*[`" sep "\"]*"))
(setq pos 0)
(while (setq pos (vl-string-position 34 str pos))
(setq str (vl-string-subst "\"\"" "\"" str pos)
pos (+ pos 2)
)
)
(strcat "\"" str "\"")
)
( str )
)
)
Here's a lisp function that will export a csv file.
The csv file contains two sections:
1.) a length summary by linetype name
2.) an individual line summary with length and linetype
csv example:
--Length Summary By LineType--
LineType,Length
CENTER,739.97
HIDDEN,1858.61
--Length Breakdown By Individual Line--
LineType,Length
CENTER,246.656
HIDDEN,309.768
HIDDEN,309.768
CENTER,246.656
HIDDEN,309.768
HIDDEN,309.768
CENTER,246.656
HIDDEN,309.768
HIDDEN,309.768
Lisp code
;;www.cadwiki.net
(defun c:test (/ s i e l fn CSVSTRING CSVSTRINGLIST DATAITEM individualLineDataList LINELENGTH LINETYPE VLAOBJECT NEWASSOC NEWLENGTH PREVIOUSLENGTH lineTypeToLengthAssoc SUMMARYENTRY
)
(if (and (setq s (ssget '((0 . "LWPOLYLINE"))))
(setq fn (getfiled "Create Output File" "" "csv" 1))
)
(progn
(setq s (_SortSSByXValue s))
(setq i (sslength s))
(setq individualLineDataList (list))
(while (setq e (ssname s (setq i (1- i))))
(setq vlaObject (vlax-ename->vla-object e))
(setq lineType (vla-get-linetype vlaObject))
(setq lineLength (vla-get-length vlaObject))
(setq dataItem (list lineType lineLength))
(setq individualLineDataList (cons dataItem individualLineDataList))
(setq summaryEntry (assoc lineType lineTypeToLengthAssoc))
(if (/= summaryEntry nil)
(progn
(setq previousLength (cdr summaryEntry))
(setq newLength (+ previousLength lineLength))
(setq newAssoc (cons lineType newLength))
(setq lineTypeToLengthAssoc (REMOVE-ASSOC-BY-KEY lineType lineTypeToLengthAssoc))
(setq lineTypeToLengthAssoc (cons newAssoc lineTypeToLengthAssoc))
)
(progn
(setq newAssoc (cons lineType lineLength))
(setq lineTypeToLengthAssoc (cons newAssoc lineTypeToLengthAssoc))
)
)
(ssdel e s)
)
)
)
(setq csvStringList (list (list "--Length Summary By LineType--")))
(setq csvStringList (cons (list "LineType" "Length") csvStringList))
(foreach assocItem lineTypeToLengthAssoc
(setq csvString (summaryAssocToStringList assocItem))
(setq csvStringList (cons csvString csvStringList))
)
(setq csvStringList (cons (list "--Length Breakdown By Individual Line--") csvStringList))
(setq csvStringList (cons (list "LineType" "Length") csvStringList))
(foreach item individualLineDataList
(setq csvString (cd:CON_All2Str item nil))
(setq csvStringList (cons csvString csvStringList))
)
(setq csvStringList (reverse csvStringList))
(if (LM:WriteCSV csvStringList fn)
(startapp "explorer" fn)
)
(princ)
)
(defun REMOVE-ASSOC-BY-KEY (assocKey assocList / newAssocList item)
(setq newAssocList nil)
(foreach item assocList
(if (not (= (car item) assocKey))
(setq newAssocList (append newAssocList (list item)))
)
)
newAssocList
)
(defun summaryAssocToStringList (assocItem / LINELENGTH LINETYPE STRINGLIST)
(setq lineType (car assocItem))
(setq lineLength (cdr assocItem))
(setq stringList (list lineType (rtos lineLength 2 2)))
)
(defun cd:CON_All2Str (Lst Mode)
(mapcar
(function
(lambda (%)
(if Mode
(vl-prin1-to-string %)
(vl-princ-to-string %)
)
)
)
Lst
)
)
(defun _SortSSByXValue (ss / lst i e add)
(if (eq (type ss) 'PICKSET)
(progn
(repeat (setq i (sslength ss))
(setq lst (cons (cons (setq e (ssname ss (setq i (1- i))))
(cadr (assoc 10 (entget e)))
)
lst
)
)
)
(setq add (ssadd))
(foreach e (vl-sort lst (function (lambda (a b) (< (cdr a) (cdr b))))) (ssadd (car e) add))
(if (> (sslength add) 0)
add
)
)
)
)
(defun LM:writecsv (lst csv / des sep)
(if (setq des (open csv "w"))
(progn
(setq sep (cond ((vl-registry-read "HKEY_CURRENT_USER\\Control Panel\\International" "sList"))
(",")
)
)
(foreach row lst (write-line (LM:lst->csv row sep) des))
(close des)
t
)
)
)
(defun LM:lst->csv (lst sep)
(if (cdr lst)
(strcat (LM:csv-addquotes (car lst) sep) sep (LM:lst->csv (cdr lst) sep))
(LM:csv-addquotes (car lst) sep)
)
)
(defun LM:csv-addquotes (str sep / pos)
(cond
((wcmatch str (strcat "*[`" sep "\"]*"))
(setq pos 0)
(while (setq pos (vl-string-position 34 str pos))
(setq str (vl-string-subst "\"\"" "\"" str pos)
pos (+ pos 2)
)
)
(strcat "\"" str "\"")
)
(str)
)
)
(define CHAR-CANVAS%
(class canvas%
(define/override (on-char evt)
(let ((c (send evt get-key-code)) (dc(send this get-dc)))
(send dc clear)
(print c)
(cond
((equal? c 'release)(void))
((member c '( #\a #\i #\u #\e #\o #\q #\é #\x))
(begin(set! tampon-key (cons c tampon-key)) (send dc draw-text (cadr (member (list->string (reverse tampon-key)) alphabet )) 30 30)
(send R-k-text insert (cadr (member (list->string (reverse tampon-key)) alphabet ))) (set! tampon-key '())))
((equal? c #\;)(begin(send R-k-text insert "。") (set! tampon-key '())))
((equal? c #\,)(begin(send R-k-text insert "、") (set! tampon-key '())))
((equal? c #\()(begin(send R-k-text insert "「") (set! tampon-key '())))
((equal? c #\))(begin(send R-k-text insert " 」") (set! tampon-key '())))
((equal? c #\&)(begin(send R-k-text insert "々") (set! tampon-key '())))
((not(member c '(#\b #\c #\d #\f #\g #\j #\k #\m #\n #\p #\r #\i #\h #\t #\s #\w #\y #\a #\e #\o #\z #\u)))(void))
((begin (set! tampon-key (cons c tampon-key))(print tampon-key))))
))
(super-new)))
It works very well (it is for writing in hiragana katakana and other characters)
I want to add to this same canvas
a feature which tells me the position of the cursor on a text
is it possible? if yes
what is the code to add?
(define/override (on-char evt)......
Or do I need a another canvas?
in this case what will be my code?
(define/override (on-char evt)......
this in order to do something similar to a "RIKAICHAN"
(define (transform-syll->mot L-romanji L-hiragana)
(let ((a '())(b'()))
(set! a (map list->string (reverse L-romanji)))
(set! b (map char->string (string->list "たべます")))
(list a b)))
(define (foo-w1 tw) ;transforme syllabe en fichier wav (if exist)
(let ((l '()))
(while (not (null? tw))
(set! l(cons (string-append (car tw )".wav")l))
(set! tw (cdr tw)))
(reverse l)))
(define (transform-mot->son L-romanji L-hiragana)
(let* ((x (transform-syll->mot L-romanji L-hiragana))
(a (car x)))
(current-directory "/Users/izuko/Desktop/japonais-new/jap-syll")
(rs-append* (map rs-read (foo-w1 a)))))
(define syllabe-R '())
(define syllabe-H '())
(define clip "")
(define Bt-dir
(new button%
(parent GP-1 )
(label "Direct")
(callback (lambda (obj evt)
(begin (set! alphabet hiragana)
(set! lecture-feld (send R-k-tex-rech get-text))
(set! LECT-HI* (cons lecture-feld LECT-HI*))
(set! LECT-ID* (cons lecture-feld LECT-ID*))
(send R-k-text insert lecture-feld)
(set! syllabe-R (transform-syll->mot tampon-wort lecture-feld))
(set! clip (transform-mot->son tampon-wort lecture-feld))
(play clip))))))
I'm trying to write let over lambda defmacro/g! in guile scheme. I have this:
(use-modules (srfi srfi-1))
(define (flatten x)
(let rec ((x x) (acc '()))
(cond ((null? x) acc)
((not (pair? x)) (cons x acc))
(else
(rec (car x)
(rec (cdr x) acc))))))
(define (g!-symbol? s)
(and (symbol? s)
(let ((symbol-string (symbol->string s)))
(and (> (string-length symbol-string) 2)
(equal? (string-downcase (substring symbol-string 0 2)) "g!")))))
(define-macro (define-macro/g! name-args . body)
(let ((syms (delete-duplicates
(filter g!-symbol? (flatten body)))))
`(define-macro ,name-args
(let ,(map
(lambda (s)
`(,s (gensym ,(substring (symbol->string s) 2))))
syms)
,#body))))
but when I try to macro expand define-macro/g! using this:
(use-modules (language tree-il))
(tree-il->scheme (macroexpand '(define-macro/g! (foo . body) `(let ((g!car ,(car body))) g!car))))
I've got this:
$15 = (if #f #f)
why I've got this result? How can I expand define-macro/g!?
I need to use this code:
(define macro '(define-macro/g! (foo . body) `(let ((g!car ,(car body))) g!car)))
(tree-il->scheme (macroexpand macro 'c '(compile load eval)))
I am trying to create a lisp function that evaluates and simplifies multiplication and addition arithmetic.
The function should work such that when the user calls a function
(simplify-Mult'(* 1 2)) it prints just 2 or
(simplify-Mult '(*0 3 3 7)) prints just 0.
So far I have this
(defun simplify-multiplication (lis)
(if (not (null lis))
(if (member '0 lis) 0
(if (member '1 lis) cdr lis
(if (listp (car lis))
(cons(simplify(car lis)))
(if (numberp (car lis))
(if (null (cdr lis))
lis
(cons (car lis) (simplify-multiplication (cdr lis)))
)
(if (eq (car lis) '+)
(cons (car lis) (simplify-multiplication (cdr lis)))
(if (eq (car lis) '*)
(cons (car lis) (simplify-multiplication (cdr lis)))
lis
)
)
)
)
)
)
)
)
You can write one single function simplify which applies the simplification rules for both multiplication and addition. If you want to recursively simplify an expression, first you have to simplify each one of the arguments and then apply the simplification rules for the corresponding operation.
The following could be a starting point:
(defun simplify (lis)
(if (atom lis)
lis
(let ((args (mapcar #'simplify (cdr lis))))
(cond
((eql (car lis) '+)
(setq args (remove 0 args))
(case (length args)
(0 0)
(1 (car args))
(otherwise (cons '+ args)) ))
((eql (car lis) '*)
(if (member 0 args)
0
(progn
(setq args (remove 1 args))
(case (length args)
(0 1)
(1 (car args))
(otherwise (cons '* args)) ))))
(T (cons (car lis) args)) ))))
You would probably want to add other simplification rules, such as (* 2 (* 3 4)) => (* 2 3 4), etc.. as well as detecting wrong expressions such as (simplify '(+)).
I am looking for some assistance, please, to extract all elements of a list of files and/or directories that have been marked in dired-mode. Essentially, if there were some way to just remove the parentheses from around the result of (mapcar (lambda (filename) (file-name-nondirectory filename)) (dired-get-marked-files)), then that would do the trick.
(start-process
"name-of-process"
"*output-buffer*"
"/usr/bin/zip"
"zip-file-name.zip"
(mapcar
(lambda (filename) (file-name-nondirectory filename))
(dired-get-marked-files)) )
The result I am seeking will look like this:
(start-process
"name-of-process"
"*output-buffer*"
"/usr/bin/zip"
"zip-file-name.zip"
"filename-number-one"
"filename-number-two"
"filename-number-three" )
EDIT:
The start-process function does not generally accept a single concatenated string of arguments. Instead, each argument must be separately spelled out (with quotation marks around each argument), or the argument can be a variable.
Here is the debugger message from the first example above -- the error occurs because there is a parentheses around the file names -- i.e., it cannot be a list.
Debugger entered--Lisp error: (wrong-type-argument stringp ("file-name-number-one" "file-name-number-two" "file-name-number-three"))
start-process("name-of-process" "*output-buffer*" "/usr/bin/zip" "zip-file-name.zip" ("file-name-number-one" "file-name-number-two" "file-name-number-three"))
eval((start-process "name-of-process" "*output-buffer*" "/usr/bin/zip" "zip-file-name.zip" (mapcar (lambda (filename) (file-name-nondirectory filename)) (dired-get-marked-files))) nil)
(cons (eval exp lexical-binding) values)
(setq values (cons (eval exp lexical-binding) values))
(let ((debug-on-error old-value)) (setq values (cons (eval exp lexical-binding) values)) (setq new-value debug-on-error))
(let ((old-value (make-symbol "t")) new-value) (let ((debug-on-error old-value)) (setq values (cons (eval exp lexical-binding) values)) (setq new-value debug-on-error)) (if (eq old-value new-value) nil (setq debug-on-error new-value)))
(if (null eval-expression-debug-on-error) (setq values (cons (eval exp lexical-binding) values)) (let ((old-value (make-symbol "t")) new-value) (let ((debug-on-error old-value)) (setq values (cons (eval exp lexical-binding) values)) (setq new-value debug-on-error)) (if (eq old-value new-value) nil (setq debug-on-error new-value))))
(let ((exp (if exp exp (read--expression "Eval: ")))) (if (null eval-expression-debug-on-error) (setq values (cons (eval exp lexical-binding) values)) (let ((old-value (make-symbol "t")) new-value) (let ((debug-on-error old-value)) (setq values (cons (eval exp lexical-binding) values)) (setq new-value debug-on-error)) (if (eq old-value new-value) nil (setq debug-on-error new-value)))) (let ((print-length (and (not (= 0 (prefix-numeric-value insert-value))) eval-expression-print-length)) (print-level (and (not (= 0 (prefix-numeric-value insert-value))) eval-expression-print-level)) (deactivate-mark)) (if insert-value (with-no-warnings (let ((standard-output (current-buffer))) (prog1 (prin1 (car values)) (if (= 0 ...) (progn ...))))) (prog1 (prin1 (car values) t) (let ((str (eval-expression-print-format ...))) (if str (princ str t)))))))
(if (active-minibuffer-window) nil (let ((exp (if exp exp (read--expression "Eval: ")))) (if (null eval-expression-debug-on-error) (setq values (cons (eval exp lexical-binding) values)) (let ((old-value (make-symbol "t")) new-value) (let ((debug-on-error old-value)) (setq values (cons (eval exp lexical-binding) values)) (setq new-value debug-on-error)) (if (eq old-value new-value) nil (setq debug-on-error new-value)))) (let ((print-length (and (not (= 0 ...)) eval-expression-print-length)) (print-level (and (not (= 0 ...)) eval-expression-print-level)) (deactivate-mark)) (if insert-value (with-no-warnings (let ((standard-output ...)) (prog1 (prin1 ...) (if ... ...)))) (prog1 (prin1 (car values) t) (let ((str ...)) (if str (princ str t))))))))
lawlist-eval-expression()
funcall-interactively(lawlist-eval-expression)
call-interactively(lawlist-eval-expression nil nil)
command-execute(lawlist-eval-expression)
What you want is to use apply with (mapcar ...) as its last argument:
(apply 'start-process
"name-of-process"
"*output-buffer*"
"/usr/bin/zip"
"zip-file-name.zip"
(mapcar #'file-name-nondirectory (dired-get-marked-files)))
Note that (mapcar #'function list) is a shorter spelling of (mapcar (lambda (arg) (function arg)) list).
combine-and-quote-strings is what you want:
(combine-and-quote-strings (mapcar (lambda (x)
(file-name-nondirectory x))
(dired-get-marked-files)))
EDIT: the following will give you a single, quoted string with internal quotes. Not sure if it'll play nicely with start-process:
(mapconcat
(lambda (x)
(concat "\"" (file-name-nondirectory x) "\""))
(dired-get-marked-files) " ")
EDIT: Righty-o, let's try this. Splice the backquoted list with ,#, then eval the whole thing:
(eval `(start-process
"name-of-process"
"*output-buffer*"
"/usr/bin/zip"
"zip-file-name.zip"
,#(mapcar
(lambda (x)
(file-name-nondirectory x))
(dired-get-marked-files))))