Question for the LISPERS.Suppose you needed to pen a couple padding functions that take a string and right or left pad it with n specified characters.
You might code it like this (naming after antiquated basic equivalents):
RSET:(defun rset ( text padding maxlen )
(substr
( (lambda ( )
(while
(<
(strlen (setq padding (strcat padding padding)))
maxlen
)
)
(setq text (strcat padding text))
)
)
(- (strlen text) (1- maxlen))
)
)
Example:(rset "text" " " 10)
==> " text"
LSET:(defun lset ( text padding maxlen )
(substr
( (lambda ( )
(while
(<
(strlen (setq padding (strcat padding padding)))
maxlen
)
)
(strcat text padding)
)
)
1
maxlen
)
)
Example:(lset "text" " " 10)
==> "text "
Then you notice there is duplicated logic, so you distil the functions by writing an auxiliary function:
SETAUX:(defun setaux ( padding maxlen )
(while
(<
(strlen (setq padding (strcat padding padding)))
maxlen
)
)
padding
)
RSET:(defun rset ( text padding maxlen )
(substr
(setq text
(strcat
(setaux padding maxlen)
text
)
)
(- (strlen text) (1- maxlen))
)
)
LSET:(defun lset ( text padding maxlen )
(substr
(strcat text (setaux padding maxlen))
1
maxlen
)
)
You're thinking it looks pretty good but then you realize, at least theoretically, that it demonstrates poor coding practice.
What poor coding practice do the rewritten functions demonstrate?
What would that practice be called?
On the other hand you realize they also demonstrate good coding practice.
What good coding practice do the rewritten functions demonstrate?
What would that practice be called?
Kerry, please hold off responding to this one, at least for a bit.