users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C interface confusion about char codes, lists and atoms...


From: emacstheviking
Subject: C interface confusion about char codes, lists and atoms...
Date: Wed, 3 Jul 2013 15:44:19 +0100

Hi,

I have been experimenting with the foreign interface and managed to confuse myself.

Given this foreign declaration:

%% :- foreign( foo( +string ), [fct_name( foo )]). %% +string => atom at call site
%% :- foreign( foo( +codes ), [fct_name( foo )]).

:- foreign( foo( +codes ), [fct_name( foo )]).

and this implementation:

// +string :: atom                ==>  char*, works
// +codes  :: character-code list ==>  char*, works as foo("Hello").
// +chars  :: character list      ==>  char*, fails on call foo("HI"), foo([64,65]). Why?

PlBool
foo(char* s)
{
  printf("FOO: ==> %s\n", s);
  return PL_TRUE;
}

My problem is that when I use "+chars" I can't then say:

    foo("Hello")

as I get a type_error so please can anybody explain to me what "character list" is and how it looks in a command line session? The flag that controls the interpretation of double-quoted strings is at its default value as I have not altered it but I am aware of its existence and the fact that "" is syntactic sugaring of lists of codes.

Thanks.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]