unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* critique: my-first-function
@ 2016-06-12 22:39 James K. Lowden
  2016-06-13  1:04 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: James K. Lowden @ 2016-06-12 22:39 UTC (permalink / raw)
  To: help-gnu-emacs

Although I've been using emacs for years, today was the first time I
set out to write a substantial (to me) function from first principles.
Below is what I came up with.  I wonder if anyone has a suggestion or
opinion on how it might have been done better, differently, or more in
the spirit of the emacs zeitgeist?  

(defun open-tall-frames ()
  "Open two tall frames."
  (interactive)
  (let ( (frame-parameters 
	  '((width . 80)
	    (height . 60)
	    (minibuffer . t)
	    (window-system . x)))
	 (frame1 (make-frame frame-parameters))
	 (frame2 (make-frame frame-parameters))
	 )
  (set-frame-position frame1 -1 0)
  (set-frame-position frame2 (- (frame-pixel-width frame1)) 0)
))

--jkl


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: critique: my-first-function
  2016-06-12 22:39 critique: my-first-function James K. Lowden
@ 2016-06-13  1:04 ` Stefan Monnier
  2016-06-13  1:08 ` Emanuel Berg
       [not found] ` <mailman.1403.1465780144.1216.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2016-06-13  1:04 UTC (permalink / raw)
  To: help-gnu-emacs

> 	 (frame1 (make-frame frame-parameters))
> 	 (frame2 (make-frame frame-parameters))
> 	 )
>   (set-frame-position frame1 -1 0)
>   (set-frame-position frame2 (- (frame-pixel-width frame1)) 0)

You can specify the frame's initial position directly when calling
`make-frame`, using parameters like `top` and `left`.


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: critique: my-first-function
  2016-06-12 22:39 critique: my-first-function James K. Lowden
  2016-06-13  1:04 ` Stefan Monnier
@ 2016-06-13  1:08 ` Emanuel Berg
       [not found] ` <mailman.1403.1465780144.1216.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2016-06-13  1:08 UTC (permalink / raw)
  To: help-gnu-emacs

"James K. Lowden" <jklowden@speakeasy.net>
writes:

> (defun open-tall-frames ()
>   "Open two tall frames."
>   (interactive)
>   (let ( (frame-parameters 
> 	  '((width . 80)
> 	    (height . 60)
> 	    (minibuffer . t)
> 	    (window-system . x)))
> 	 (frame1 (make-frame frame-parameters))
> 	 (frame2 (make-frame frame-parameters))
> 	 )
>   (set-frame-position frame1 -1 0)
>   (set-frame-position frame2 (- (frame-pixel-width frame1)) 0)
> ))

`let' should be `let*' since "frame-parameters"
are used inside the same `let'.

Some more subjective views:

As for style, I think you can align the
data items (lines 5-8).

Instead of "frame1" "frame2", name them after
some property.

And, on line 13, there is a computation, which
I would name and put in the `let' clause as
well. So you set up all data there, and then
only have execution below the `let' - makes it
look good.

-- 
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 48 Blogomatic articles -                   




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: critique: my-first-function
       [not found] ` <mailman.1403.1465780144.1216.help-gnu-emacs@gnu.org>
@ 2016-06-15  1:47   ` James K. Lowden
  2016-06-15  4:43     ` Drew Adams
  0 siblings, 1 reply; 5+ messages in thread
From: James K. Lowden @ 2016-06-15  1:47 UTC (permalink / raw)
  To: help-gnu-emacs

On Mon, 13 Jun 2016 03:08:47 +0200
Emanuel Berg <embe8573@student.uu.se> wrote:

My thanks to both you and Stefan.  

> `let' should be `let*' since "frame-parameters"
> are used inside the same `let'.

It's a good thing you mentioned that!  The next morning, I had to
restart emacs (because ssh mumble something timeout) and my function
failed.  It had worked the day before because 

>   (let ( (frame-parameters 

frame-parameters happened to have been defined globally during
testing.  Adding the "*" fixed it instantly.  

Is the "*" a convention of some kind that I should be aware of?  

> Instead of "frame1" "frame2", name them after
> some property.

Well, one day the whole thing will be a recursive call over a list of
coordinates.  The frames don't deserve names, but I couldn't see my way
to creating the list.  

Thanks again.  

--jkl


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: critique: my-first-function
  2016-06-15  1:47   ` James K. Lowden
@ 2016-06-15  4:43     ` Drew Adams
  0 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2016-06-15  4:43 UTC (permalink / raw)
  To: James K. Lowden, help-gnu-emacs

> Is the "*" a convention of some kind that I should be aware of?

Sort of.  Some functions that are similar to other functions use
the same base name as the latter, but with a `*' suffix.  This is
more prominent in some lisps.

For example, Common Lisp has `do' and `do*'.  `do*' is to `do' as
`let*' is to `let': the bindings of the `*' versions are evaluated
sequentially.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-06-15  4:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-12 22:39 critique: my-first-function James K. Lowden
2016-06-13  1:04 ` Stefan Monnier
2016-06-13  1:08 ` Emanuel Berg
     [not found] ` <mailman.1403.1465780144.1216.help-gnu-emacs@gnu.org>
2016-06-15  1:47   ` James K. Lowden
2016-06-15  4:43     ` Drew Adams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).