* ELisp - Making a list from a function returning a number @ 2020-12-17 11:42 steve-humphreys 2020-12-18 2:26 ` steve-humphreys 0 siblings, 1 reply; 9+ messages in thread From: steve-humphreys @ 2020-12-17 11:42 UTC (permalink / raw) To: Help Gnu Emacs I have written a function to return time as a number so I can set the temporal grid in org-agenda. I was previously using number-sequence until someone fount a problem. Now I have timfutur to give me the next time (time interval "tsk" after time "tim") (tim (number-sequence tstr tend tskp)) So what I have remaining to do is to make a list of numbers representing the times when the agenda grids are displayed. (defun timfutur (tim tsk) (let* ( (thr (/ tim 100)) (tmn (- tim (* thr 100))) (tinc_mn (+ tmn tsk)) (tinc_hr (/ (+ tmn tsk) 60)) (tinc_mn (- tinc_mn (* tinc_hr 60))) (thr_futur (* (+ thr tinc_hr) 100)) (tmn_futur tinc_mn) (tim_out (+ thr_futur tmn_futur)) ) ;; --- body of let ---- tim_out )) ; function returns last form ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ELisp - Making a list from a function returning a number 2020-12-17 11:42 ELisp - Making a list from a function returning a number steve-humphreys @ 2020-12-18 2:26 ` steve-humphreys 2020-12-18 3:01 ` steve-humphreys 0 siblings, 1 reply; 9+ messages in thread From: steve-humphreys @ 2020-12-18 2:26 UTC (permalink / raw) To: steve-humphreys; +Cc: Help Gnu Emacs I have now started constructing my function but get many problems. (defun timgrid () (setq tstr 800) (setq tend 1300) (setq tpd 34) (setq i 0) (setq tim tstr) (setq tlist '(tim)) (dotimes (i 4) (setq tfr (timfutur (tim tpd))) (setq tim tfr) (setq tlist (append (tlist) (tim))) )) > Sent: Thursday, December 17, 2020 at 12:42 PM > From: steve-humphreys@gmx.com > To: "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: ELisp - Making a list from a function returning a number > > > I have written a function to return time as a number so I can set the temporal grid > in org-agenda. > > I was previously using number-sequence until someone fount a problem. Now I have timfutur to > give me the next time (time interval "tsk" after time "tim") > > (tim (number-sequence tstr tend tskp)) > > So what I have remaining to do is to make a list of numbers representing the times when the > agenda grids are displayed. > > > (defun timfutur (tim tsk) > > (let* ( (thr (/ tim 100)) > (tmn (- tim (* thr 100))) > > (tinc_mn (+ tmn tsk)) > (tinc_hr (/ (+ tmn tsk) 60)) > (tinc_mn (- tinc_mn (* tinc_hr 60))) > > (thr_futur (* (+ thr tinc_hr) 100)) > (tmn_futur tinc_mn) > (tim_out (+ thr_futur tmn_futur)) ) > ;; --- body of let ---- > tim_out )) ; function returns last form > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ELisp - Making a list from a function returning a number 2020-12-18 2:26 ` steve-humphreys @ 2020-12-18 3:01 ` steve-humphreys 2020-12-18 14:43 ` Emanuel Berg via Users list for the GNU Emacs text editor 0 siblings, 1 reply; 9+ messages in thread From: steve-humphreys @ 2020-12-18 3:01 UTC (permalink / raw) To: steve-humphreys; +Cc: Help Gnu Emacs This is my new function (defun timgrid () (let* ( (tstr 800) (tend 1300) (tpd 34) (i 0) (tim tstr) tim tfr ) ;; ----- body of let ----- (dotimes (i 4) (message "tim tpd: %d %d" tim tpd) (setq tfr (timfutur tim tpd)) (message "tim: %d" tim) ;;(setq tlist (append 'tlist (list tim))) (setq tim tfr)) )) > Sent: Friday, December 18, 2020 at 3:26 AM > From: steve-humphreys@gmx.com > To: steve-humphreys@gmx.com > Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: Re: ELisp - Making a list from a function returning a number > > I have now started constructing my function but get many problems. > > (defun timgrid () > > (setq tstr 800) > (setq tend 1300) > (setq tpd 34) > > (setq i 0) > (setq tim tstr) > (setq tlist '(tim)) > (dotimes (i 4) > (setq tfr (timfutur (tim tpd))) > (setq tim tfr) > (setq tlist (append (tlist) (tim))) )) > > > > Sent: Thursday, December 17, 2020 at 12:42 PM > > From: steve-humphreys@gmx.com > > To: "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > > Subject: ELisp - Making a list from a function returning a number > > > > > > I have written a function to return time as a number so I can set the temporal grid > > in org-agenda. > > > > I was previously using number-sequence until someone fount a problem. Now I have timfutur to > > give me the next time (time interval "tsk" after time "tim") > > > > (tim (number-sequence tstr tend tskp)) > > > > So what I have remaining to do is to make a list of numbers representing the times when the > > agenda grids are displayed. > > > > > > (defun timfutur (tim tsk) > > > > (let* ( (thr (/ tim 100)) > > (tmn (- tim (* thr 100))) > > > > (tinc_mn (+ tmn tsk)) > > (tinc_hr (/ (+ tmn tsk) 60)) > > (tinc_mn (- tinc_mn (* tinc_hr 60))) > > > > (thr_futur (* (+ thr tinc_hr) 100)) > > (tmn_futur tinc_mn) > > (tim_out (+ thr_futur tmn_futur)) ) > > ;; --- body of let ---- > > tim_out )) ; function returns last form > > > > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ELisp - Making a list from a function returning a number 2020-12-18 3:01 ` steve-humphreys @ 2020-12-18 14:43 ` Emanuel Berg via Users list for the GNU Emacs text editor 2020-12-18 17:53 ` Jean Louis 0 siblings, 1 reply; 9+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-12-18 14:43 UTC (permalink / raw) To: help-gnu-emacs steve-humphreys wrote: > This is my new function > > (defun timgrid () > > (let* ( (tstr 800) > (tend 1300) > (tpd 34) > (i 0) > (tim tstr) > tim tfr ) > ;; ----- body of let ----- > (dotimes (i 4) > (message "tim tpd: %d %d" tim tpd) > (setq tfr (timfutur tim tpd)) > (message "tim: %d" tim) > ;;(setq tlist (append 'tlist (list tim))) > (setq tim tfr)) )) Please, 1. use more understandable language. this is Lisp, not assembly language... 2. remove blank lines and commented out lines 3. don't use comments that do not add any information (e.g., "body of let" - but that is already plain and true, by definition) 4. use the normal indentation space for Elisp, in `elisp-mode' two spaces 5. again, don't use `setq' in function bodies when there is no need, you already have the vars in let*, do all computation there (add more vars if necessary, for clarity, even) I'm not saying this to be disrespectful, instead trust me that it will bring your game up A LOT and also people will be more likely to communicate with you - more, but also better since you help not only yourself but also anyone reading and possibly using your code... -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ELisp - Making a list from a function returning a number 2020-12-18 14:43 ` Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-12-18 17:53 ` Jean Louis 2020-12-20 5:03 ` Emanuel Berg via Users list for the GNU Emacs text editor 0 siblings, 1 reply; 9+ messages in thread From: Jean Louis @ 2020-12-18 17:53 UTC (permalink / raw) To: help-gnu-emacs * Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2020-12-18 17:45]: > steve-humphreys wrote: > > > This is my new function > > > > (defun timgrid () > > > > (let* ( (tstr 800) > > (tend 1300) > > (tpd 34) > > (i 0) > > (tim tstr) > > tim tfr ) > > ;; ----- body of let ----- > > (dotimes (i 4) > > (message "tim tpd: %d %d" tim tpd) > > (setq tfr (timfutur tim tpd)) > > (message "tim: %d" tim) > > ;;(setq tlist (append 'tlist (list tim))) > > (setq tim tfr)) )) > > Please, > > 1. use more understandable language. this is Lisp, not > assembly language... No, quite contrary. LISP allows for any paradigm of programming. Linear programming, etc. It does not matter. I see no problem there like you see it. Many of my command line tools in Common Lisp only load other programs and invoke one let. There are conventions, but first LISP programs was not written in any of our today's conventions. I would say that LISP convention is good that variables may be described easier. Instead of `tstr' one could say `time-start' or instead `tend' one could freely say `time-end'. Then again I will sometimes use just a, b, c for variables. > 2. remove blank lines and commented out lines For one's own understanding this may help. Step by step. Learning goes on gradient. > 3. don't use comments that do not add any information (e.g., > "body of let" - but that is already plain and true, by > definition) That is what you know on a different gradient. Even more comments would be required on beginning gradient and this in all programming languages. Advanced programmers need no comments, they read the code. I have little difficulties reading scheme code due to little bit more functional way of programming, but reading Emacs functions is often terrible for me due to way how they are written. > 4. use the normal indentation space for Elisp, in `elisp-mode' two > spaces It may be hard to understand for new Elisp programmer what you mean here. I do not use nothing, I use elisp-mode and I press TAB or M-q to indent everything in a region. I would not even know how it should be indented if I would not be using emacs lisp mode. > 5. again, don't use `setq' in function bodies when there is no > need, you already have the vars in let*, do all computation > there (add more vars if necessary, for clarity, even) Especially in a list within `let' form there is no problem in using `setq'. In that above example I can fully understand that way of doing things as it gives clearer picture on what is happening. First comes inception then shape. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ELisp - Making a list from a function returning a number 2020-12-18 17:53 ` Jean Louis @ 2020-12-20 5:03 ` Emanuel Berg via Users list for the GNU Emacs text editor 2020-12-20 6:23 ` Jean Louis 0 siblings, 1 reply; 9+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-12-20 5:03 UTC (permalink / raw) To: help-gnu-emacs Jean Louis wrote: > No, quite contrary. LISP allows for any paradigm of > programming. Linear programming, etc. It does not matter. > I see no problem there like you see it. Yes, I'm talking Elisp conventions then... > Many of my command line tools in Common Lisp only load other > programs and invoke one let. There are conventions, but > first LISP programs was not written in any of our > today's conventions. Yes, I'm talking the present then... >> 2. remove blank lines and commented out lines > > For one's own understanding this may help. Step by step. > Learning goes on gradient. When one posts here, and for one's own karma, it is better to make it as good as possible, even (especially) when it doesn't work. >> 3. don't use comments that do not add any information (e.g., >> "body of let" - but that is already plain and true, by >> definition) > > That is what you know on a different gradient. Even more comments > would be required on beginning gradient and this in all programming > languages. Advanced programmers need no comments, they read the > code. One should comment what is unusual, counterintuitive or needs further explanation. For example something that looks wrong, but is right. Advanced programmers do this all the time I was about to say, but luckily this doesn't happen all the time :) In Elisp one can also add little helpers that can be evaluated, e.g. ;; (setq latex-mode-hook nil) (defun latex-mode-hook-f () (set-latex-keys) (auto-fill-mode) (abbrev-mode) (lines) ) (add-hook 'latex-mode-hook #'latex-mode-hook-f) One can also use comments as headers, this works especially well since they get another color with font lock, namely the font-lock-comment-face and font-lock-comment-delimiter-face faces. For example: (let ((the-map gnus-group-mode-map)) (disable-super-global-keys the-map) (set-close-key the-map) (set-vertical-keys the-map) ;; show (define-key the-map "f" #'gnus-group-list-few-groups-sort) (define-key the-map "l" #'gnus-group-list-all-groups-sort) ;; goto (define-key the-map "m" #'gnus-group-show-mails) (define-key the-map "s" #'gnus-group-show-sent) ;; group (define-key the-map "3" #'gnus-group-unsubscribe-current-group) (define-key the-map "\C-k" nil) ; disable `gnus-group-kill-group' (define-key the-map "A" #'gnus-group-make-group) (define-key the-map "a" #'gnus-group-post-news-to-group-at-point) ;; servers (define-key the-map "o" #'gnus-server-open-all-servers) (define-key the-map "S" #'gnus-group-enter-server-mode) ;; misc (define-key the-map "\M-0" #'gnus-undo) (define-key the-map "g" #'gnus-group-get-new-news-verbose) (define-key the-map "u" #'gnus-score-load-files) ) So the use of comments should be put to use sensibly by beginner and advanced programmers alike... >> 4. use the normal indentation space for Elisp, in >> `elisp-mode' two spaces > > It may be hard to understand for new Elisp programmer what > you mean here. I do not use nothing, I use elisp-mode and > I press TAB or M-q to indent everything in a region. I would > not even know how it should be indented if I would not be > using emacs lisp mode. OK, well two spaces is the standard and yes auto indentation is very useful. >> 5. again, don't use `setq' in function bodies when there is >> no need, you already have the vars in let*, do all >> computation there (add more vars if necessary, for >> clarity, even) > > Especially in a list within `let' form there is no problem > in using `setq'. In that above example I can fully > understand that way of doing things as it gives clearer > picture on what is happening. Yes, there is a problem with `setq' in functions and that is it will silently create a global variable if one makes a typo, also it makes the code more unclear, also often it isn't even needed since one can just as easily do all the computation using `let'. On is using let anyway so why don't do it there anyway? -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ELisp - Making a list from a function returning a number 2020-12-20 5:03 ` Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-12-20 6:23 ` Jean Louis 2020-12-20 6:30 ` Christopher Dimech 2020-12-20 7:01 ` Emanuel Berg via Users list for the GNU Emacs text editor 0 siblings, 2 replies; 9+ messages in thread From: Jean Louis @ 2020-12-20 6:23 UTC (permalink / raw) To: help-gnu-emacs * Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2020-12-20 08:04]: > > For one's own understanding this may help. Step by step. > > Learning goes on gradient. > > When one posts here, and for one's own karma, it is better to > make it as good as possible, even (especially) when it > doesn't work. It depends of the level of a programmer. When person is trying to understand basic functions then it would be too steep gradient to ask person to do more than the basics, when even basics are not explained. Teaching shall be gradual, it is known from school levels. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ELisp - Making a list from a function returning a number 2020-12-20 6:23 ` Jean Louis @ 2020-12-20 6:30 ` Christopher Dimech 2020-12-20 7:01 ` Emanuel Berg via Users list for the GNU Emacs text editor 1 sibling, 0 replies; 9+ messages in thread From: Christopher Dimech @ 2020-12-20 6:30 UTC (permalink / raw) To: Jean Louis; +Cc: help-gnu-emacs > Sent: Sunday, December 20, 2020 at 11:53 AM > From: "Jean Louis" <bugs@gnu.support> > To: help-gnu-emacs@gnu.org > Subject: Re: ELisp - Making a list from a function returning a number > > * Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2020-12-20 08:04]: > > > For one's own understanding this may help. Step by step. > > > Learning goes on gradient. > > > > When one posts here, and for one's own karma, it is better to > > make it as good as possible, even (especially) when it > > doesn't work. > > It depends of the level of a programmer. When person is trying to > understand basic functions then it would be too steep gradient to ask > person to do more than the basics, when even basics are not explained. One enlightened person indeed. > Teaching shall be gradual, it is known from school levels. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: ELisp - Making a list from a function returning a number 2020-12-20 6:23 ` Jean Louis 2020-12-20 6:30 ` Christopher Dimech @ 2020-12-20 7:01 ` Emanuel Berg via Users list for the GNU Emacs text editor 1 sibling, 0 replies; 9+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-12-20 7:01 UTC (permalink / raw) To: help-gnu-emacs Jean Louis wrote: >> When one posts here, and for one's own karma, it is better >> to make it as good as possible, even (especially) when it >> doesn't work. > > It depends of the level of a programmer. [...] Anyone can remove commented-out and blank lines. Just hit C-k a couple of times. -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-12-20 7:01 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-12-17 11:42 ELisp - Making a list from a function returning a number steve-humphreys 2020-12-18 2:26 ` steve-humphreys 2020-12-18 3:01 ` steve-humphreys 2020-12-18 14:43 ` Emanuel Berg via Users list for the GNU Emacs text editor 2020-12-18 17:53 ` Jean Louis 2020-12-20 5:03 ` Emanuel Berg via Users list for the GNU Emacs text editor 2020-12-20 6:23 ` Jean Louis 2020-12-20 6:30 ` Christopher Dimech 2020-12-20 7:01 ` Emanuel Berg via Users list for the GNU Emacs text editor
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.