Author Topic: I'm not understanding what is going on here.  (Read 1000 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17461
Re: I'm not understanding what is going on here.
« Reply #15 on: September 09, 2019, 08:09:51 PM »
On my phone, forgive if goes wack:

Code: [Select]
(defun _strip-prefix ( pfx text / i )
    (if (eq (strlen pfx) (setq i (vl-string-mismatch pfx text 0 0 t)))
        (substr text (1+ i))
        text
    )
)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Greg B

  • Seagull
  • Posts: 12336
  • Tell me a Joke!
Re: I'm not understanding what is going on here.
« Reply #16 on: September 10, 2019, 08:56:57 AM »
Cab,
I understand how vl-string-trim-* works (at least I thought I did), but the issue I'm having is that it works correctly EXCEPT when the expected return string begins with E, F, I, P, R, AND X.
I don't understand why.
You called for the characters "P, R, E, F, I, X, :, and " " to be removed from the left and they were.
As characters A and D were not included as characters to trim that's what the results started at.

Oh My!  That is funny!

Lee Mac

  • Seagull
  • Posts: 12282
  • London, England
Re: I'm not understanding what is going on here.
« Reply #17 on: September 10, 2019, 05:04:13 PM »
Lee, (LTRIM "a," "a,bc")

Escaping wildcards was too messy for my liking; revised approach -
Code - Auto/Visual Lisp: [Select]
  1. (defun ltrim ( pre str )
  2.     (if (and (/= "" pre) (= 0 (vl-string-search pre str)))
  3.         (ltrim pre (substr str (1+ (strlen pre))))
  4.         str
  5.     )
  6. )

MP

  • Seagull
  • Posts: 17461
Re: I'm not understanding what is going on here.
« Reply #18 on: September 10, 2019, 05:43:59 PM »
Simply because lispin' be fun ...

(defun _strip-prefix ( prefix string )
    (   (lambda (f p s i)
            (while (f p s) (setq i (1+ i) p (cdr p) s (cdr s)))
            (substr string (1+ i))
        )
        (lambda (p s) (and p (eq (car p) (car s))))
        (vl-string->list (strcase prefix))
        (vl-string->list (strcase string))
        0
    )
)


error | retry | abort | ignore
« Last Edit: September 10, 2019, 06:11:11 PM by MP »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Lee Mac

  • Seagull
  • Posts: 12282
  • London, England
Re: I'm not understanding what is going on here.
« Reply #19 on: September 10, 2019, 05:55:52 PM »
_$ (_strip-prefix "prefix" "preliminary")
"liminary"


 :wink:

MP

  • Seagull
  • Posts: 17461
Re: I'm not understanding what is going on here.
« Reply #20 on: September 10, 2019, 06:09:56 PM »
lol, didn't think it thru: fun but nfg :-D
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Lee Mac

  • Seagull
  • Posts: 12282
  • London, England
Re: I'm not understanding what is going on here.
« Reply #21 on: September 10, 2019, 06:13:23 PM »
Another variation... (this is starting to feel like one of those good ol' challenge threads...)

Code - Auto/Visual Lisp: [Select]
  1. (defun ltrim ( pre str )
  2.     (   (lambda ( a b / c )
  3.             (setq c (vl-member-if-not '(lambda ( x ) (and (= x (car a)) (setq a (cdr a)))) b))
  4.             (vl-list->string (if a b (cdr c)))
  5.         )
  6.         (vl-string->list pre)
  7.         (vl-string->list str)
  8.     )
  9. )


VovKa

  • Swamp Rat
  • Posts: 1155
  • Ukraine
Re: I'm not understanding what is going on here.
« Reply #22 on: September 10, 2019, 06:49:53 PM »
no one wants to post the simplest solution....
Rube Goldberg would love this thread :)

Jeff H

  • Needs a day job
  • Posts: 6045
Re: I'm not understanding what is going on here.
« Reply #23 on: September 10, 2019, 06:51:31 PM »
And now they have three problems, because of French comments...
:-D

VovKa

  • Swamp Rat
  • Posts: 1155
  • Ukraine
Re: I'm not understanding what is going on here.
« Reply #24 on: September 10, 2019, 06:53:55 PM »
(ltrim "" "ab")

MP

  • Seagull
  • Posts: 17461
Re: I'm not understanding what is going on here.
« Reply #25 on: September 10, 2019, 07:00:56 PM »
(ltrim "" "ab")
Coded blind on my phone ...

(defun _strip-prefix ( pfx text )
    (substr
        text
        (1+ (vl-string-mismatch pfx text 0 0 t))
    )
)
« Last Edit: September 11, 2019, 06:21:43 PM by MP »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

VovKa

  • Swamp Rat
  • Posts: 1155
  • Ukraine
Re: I'm not understanding what is going on here.
« Reply #26 on: September 10, 2019, 07:21:37 PM »
(_strip-prefix "ab" "ac")

MP

  • Seagull
  • Posts: 17461
Re: I'm not understanding what is going on here.
« Reply #27 on: September 10, 2019, 08:02:33 PM »
In mah defence it was grossly crowded on the train.  :whistling:
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Lee Mac

  • Seagull
  • Posts: 12282
  • London, England
Re: I'm not understanding what is going on here.
« Reply #28 on: September 11, 2019, 04:30:35 PM »
no one wants to post the simplest solution....
Rube Goldberg would love this thread :)

Are you saying you wish to contribute with something simpler than already posted? :-)

VovKa

  • Swamp Rat
  • Posts: 1155
  • Ukraine
Re: I'm not understanding what is going on here.
« Reply #29 on: September 11, 2019, 06:25:59 PM »
Are you saying you wish to contribute with something simpler than already posted? :-)
i think this simple vanilla solution:
(if (= pref (substr str 1 (setq l (strlen pref))))
  (substr str (1+ l))
  str
)
must have been posted first  :angel: