unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* [modules] Possible return values of the env->type_of?
@ 2018-06-22 14:41 Kaushal Modi
  2018-06-22 17:10 ` Kaushal Modi
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Kaushal Modi @ 2018-06-22 14:41 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list, Aurélien Aptel

Hello,

What are all the possible return values of the type_of function in the
Dynamic Modules API?

I am playing with Nim Emacs Modules[1], and interestingly the symbol
returned by type_of for lists is 'cons too.

From [2]:

(ert-deftest modtest-get-type ()
  (should (eq 'string (modtest-get-type "abc")))
  (should (eq 'integer (modtest-get-type 42)))
  (should (eq 'float (modtest-get-type 42.0)))
  (should (eq 'symbol (modtest-get-type nil)))
  (should (eq 'symbol (modtest-get-type t)))
  (should (eq 'symbol (modtest-get-type '())))
  (should (eq 'cons (modtest-get-type (cons 1 2))))
  (should (eq 'cons (modtest-get-type '(1 . 2))))
  (should (eq 'cons (modtest-get-type '(1 2 3)))) ;Interestingly, this is a
"cons" too.
  (should (eq 'cons (modtest-get-type (list 1 2 3))))) ;.. and this too!

Below code[3] is in Nim that creates that Elisp modtest-get-type function;
it's a light wrapper that calls the type_of Modules API function:

emacs.defun(get_type, 1):
  ## Returns the Emacs-Lisp symbol of the argument type.
  env.type_of(env, args[0])

Is this expected? I was expecting the type symbol returned for the last two
tests above to be 'list.


[1]: https://github.com/kaushalmodi/nim-emacs-module
[2]:
https://github.com/yuutayamada/nim-emacs-module/blob/f7ee0c886c67707612c6b2a62f17025b083e2aca/test/test-modtest.el#L30-L40
[3]:
https://github.com/yuutayamada/nim-emacs-module/blob/f7ee0c886c67707612c6b2a62f17025b083e2aca/test/modtest.nim#L161-L163
-- 

Kaushal Modi


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

* Re: [modules] Possible return values of the env->type_of?
  2018-06-22 14:41 [modules] Possible return values of the env->type_of? Kaushal Modi
@ 2018-06-22 17:10 ` Kaushal Modi
  2018-06-22 17:38 ` Aurélien Aptel
  2018-06-22 18:10 ` Eli Zaretskii
  2 siblings, 0 replies; 8+ messages in thread
From: Kaushal Modi @ 2018-06-22 17:10 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list, Aurélien Aptel

On Fri, Jun 22, 2018 at 10:41 AM Kaushal Modi <kaushal.modi@gmail.com>
wrote:

> Is this expected?
>

Looks like that's a yes.

The type_of API function returns whatever type-of[1] returns in Emacs.

[1]:
http://git.savannah.gnu.org/cgit/emacs.git/tree/src/data.c?id=5583e6460c38c5d613e732934b066421349a5259#n204
-- 

Kaushal Modi


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

* Re: [modules] Possible return values of the env->type_of?
  2018-06-22 14:41 [modules] Possible return values of the env->type_of? Kaushal Modi
  2018-06-22 17:10 ` Kaushal Modi
@ 2018-06-22 17:38 ` Aurélien Aptel
  2018-06-22 17:52   ` Kaushal Modi
  2018-06-22 20:58   ` Drew Adams
  2018-06-22 18:10 ` Eli Zaretskii
  2 siblings, 2 replies; 8+ messages in thread
From: Aurélien Aptel @ 2018-06-22 17:38 UTC (permalink / raw)
  To: kaushal.modi; +Cc: help-gnu-emacs

Le ven. 22 juin 2018 à 07:41, Kaushal Modi <kaushal.modi@gmail.com> a écrit :
> I am playing with Nim Emacs Modules[1], and interestingly the symbol returned by type_of for lists is 'cons too.

That's because lists are cons: (list 1 2 3) and (cons 1 (cons 2 (cons
3 nil))) eval to the same thing.

Perhaps you'll find Philip's doc useful:
https://phst.github.io/emacs-modules#type_of



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

* Re: [modules] Possible return values of the env->type_of?
  2018-06-22 17:38 ` Aurélien Aptel
@ 2018-06-22 17:52   ` Kaushal Modi
  2018-06-22 18:16     ` Eli Zaretskii
  2018-12-25 16:13     ` Philipp Stephani
  2018-06-22 20:58   ` Drew Adams
  1 sibling, 2 replies; 8+ messages in thread
From: Kaushal Modi @ 2018-06-22 17:52 UTC (permalink / raw)
  To: Aurélien Aptel, Philipp Stephani; +Cc: help-gnu-emacs

Hello Aurélie,

On Fri, Jun 22, 2018 at 1:38 PM Aurélien Aptel <aurelien.aptel@gmail.com>
wrote:

>
> That's because lists are cons: (list 1 2 3) and (cons 1 (cons 2 (cons
> 3 nil))) eval to the same thing.
>

Yes. Thank you. I realized that after I looked at C-h f type-of:

> Return a symbol representing the type of OBJECT.
> The symbol returned names the object’s basic type;

So the "basic" is the key :)


> Perhaps you'll find Philip's doc useful:
> https://phst.github.io/emacs-modules#type_of
>

Yes! That's where I figured out the relationship between env->type_of and
type-of.

@Philipp Can that documentation be made part of the Emacs Manual? It's
really useful for folks like me who don't know C. In your doc, you say:

> Because the module API is a C API, you have to be familiar with C to
write Emacs modules.

But that doesn't seem to be the case for me :) Nim provides enough
abstraction to use this API and make the code readable just like Python.
This is what I am working on[1].

[1]:
https://github.com/kaushalmodi/nim-emacs-module/blob/test-whole-emacs-module/test/modtest.nim
-- 

Kaushal Modi


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

* Re: [modules] Possible return values of the env->type_of?
  2018-06-22 14:41 [modules] Possible return values of the env->type_of? Kaushal Modi
  2018-06-22 17:10 ` Kaushal Modi
  2018-06-22 17:38 ` Aurélien Aptel
@ 2018-06-22 18:10 ` Eli Zaretskii
  2 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2018-06-22 18:10 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Kaushal Modi <kaushal.modi@gmail.com>
> Date: Fri, 22 Jun 2018 10:41:35 -0400
> 
>   (should (eq 'cons (modtest-get-type '(1 2 3)))) ;Interestingly, this is a
> "cons" too.
>   (should (eq 'cons (modtest-get-type (list 1 2 3))))) ;.. and this too!
> 
> Below code[3] is in Nim that creates that Elisp modtest-get-type function;
> it's a light wrapper that calls the type_of Modules API function:
> 
> emacs.defun(get_type, 1):
>   ## Returns the Emacs-Lisp symbol of the argument type.
>   env.type_of(env, args[0])
> 
> Is this expected? I was expecting the type symbol returned for the last two
> tests above to be 'list.

There's no such type as 'list', it's just a cons cell with a special
cdr.



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

* Re: [modules] Possible return values of the env->type_of?
  2018-06-22 17:52   ` Kaushal Modi
@ 2018-06-22 18:16     ` Eli Zaretskii
  2018-12-25 16:13     ` Philipp Stephani
  1 sibling, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2018-06-22 18:16 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Kaushal Modi <kaushal.modi@gmail.com>
> Date: Fri, 22 Jun 2018 13:52:44 -0400
> Cc: help-gnu-emacs@gnu.org
> 
> @Philipp Can that documentation be made part of the Emacs Manual?

IMO, it needs to be rewritten to fit to the manual's style and
methodology.



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

* RE: [modules] Possible return values of the env->type_of?
  2018-06-22 17:38 ` Aurélien Aptel
  2018-06-22 17:52   ` Kaushal Modi
@ 2018-06-22 20:58   ` Drew Adams
  1 sibling, 0 replies; 8+ messages in thread
From: Drew Adams @ 2018-06-22 20:58 UTC (permalink / raw)
  To: Aurélien Aptel, kaushal.modi; +Cc: help-gnu-emacs

> That's because lists are cons:
                ^
            non-empty



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

* Re: [modules] Possible return values of the env->type_of?
  2018-06-22 17:52   ` Kaushal Modi
  2018-06-22 18:16     ` Eli Zaretskii
@ 2018-12-25 16:13     ` Philipp Stephani
  1 sibling, 0 replies; 8+ messages in thread
From: Philipp Stephani @ 2018-12-25 16:13 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: help-gnu-emacs, Aurélien Aptel

Am Fr., 22. Juni 2018 um 19:52 Uhr schrieb Kaushal Modi
<kaushal.modi@gmail.com>:
>
>> Perhaps you'll find Philip's doc useful:
>> https://phst.github.io/emacs-modules#type_of
>
>
> Yes! That's where I figured out the relationship between env->type_of and  type-of.
>
> @Philipp Can that documentation be made part of the Emacs Manual?

Eli has now written a manual section about modules, which should
contain similar information.

> It's really useful for folks like me who don't know C. In your doc, you say:
>
> > Because the module API is a C API, you have to be familiar with C to write Emacs modules.
>
> But that doesn't seem to be the case for me :) Nim provides enough abstraction to use this API and make the code readable just like Python. This is what I am working on[1].
>
> [1]: https://github.com/kaushalmodi/nim-emacs-module/blob/test-whole-emacs-module/test/modtest.nim

That's great! What I mean is "you have to know enough about syntax and
semantics of C to use the module API correctly", not "you have to know
every detail of C". In particular, the lifetime and threading issues
are quite subtle.



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

end of thread, other threads:[~2018-12-25 16:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-22 14:41 [modules] Possible return values of the env->type_of? Kaushal Modi
2018-06-22 17:10 ` Kaushal Modi
2018-06-22 17:38 ` Aurélien Aptel
2018-06-22 17:52   ` Kaushal Modi
2018-06-22 18:16     ` Eli Zaretskii
2018-12-25 16:13     ` Philipp Stephani
2018-06-22 20:58   ` Drew Adams
2018-06-22 18:10 ` Eli Zaretskii

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).