Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Scheme Programming Language

identifier? vs. symbol?


The new syntax-case library introduces a new predicate "identifier?".
Isn't this just "symbol?" by a different name? Can someone explain the
difference?

Note: If the answer is "not all symbols are valid identifiers", then
can you give an example, because I can't think of one.

Thanks.

Brian.

> Note: If the answer is "not all symbols are valid identifiers", then
> can you give an example, because I can't think of one.

not all identifiers are symbols, some carry lexical information.
On Jun 4, 8:43 am, DETmaM@gmx.de wrote:

> > Note: If the answer is "not all symbols are valid identifiers", then
> > can you give an example, because I can't think of one.

> not all identifiers are symbols, some carry lexical information.

Thanks. So an identifier would either be a symbol, or a symbol with
added scoping information? Is that correct?
On Jun 4, 4:47 pm, bcbarnes <brian.bar@amd.com> wrote:

> On Jun 4, 8:43 am, DETmaM@gmx.de wrote:

> > > Note: If the answer is "not all symbols are valid identifiers", then
> > > can you give an example, because I can't think of one.

> > not all identifiers are symbols, some carry lexical information.

> Thanks. So an identifier would either be a symbol, or a symbol with
> added scoping information? Is that correct?

Yes :)
On Jun 4, 10:01 am, DETmaM@gmx.de wrote:

> On Jun 4, 4:47 pm, bcbarnes <brian.bar@amd.com> wrote:

> > On Jun 4, 8:43 am, DETmaM@gmx.de wrote:

> > > > Note: If the answer is "not all symbols are valid identifiers", then
> > > > can you give an example, because I can't think of one.

> > > not all identifiers are symbols, some carry lexical information.

> > Thanks. So an identifier would either be a symbol, or a symbol with
> > added scoping information? Is that correct?

> Yes :)

One final question, then:

Does this imply that "symbol?" would return #f for such an object? And
would "symbol->string" return a violation?

bcbarnes skrev:

Welcome to DrScheme, version 370.2-svn29may2007 [3m].
Language: Pretty Big (includes MrEd and Advanced Student)

 > (identifier? 'foo)
#f

 > (identifier? (syntax foo))
#t

 > (symbol? (syntax foo))
#f

Or use the #' shorthand for (syntax ...)

 > (identifier? #'foo)
#t

 > (symbol? #'foo)
#f

 > (symbol->string (syntax-object->datum #'foo))
"foo"

NOTE: syntax-object->datum is called syntax->datum in R6RS.

--
Jens Axel Sgaard

bcbarnes wrote:
> The new syntax-case library introduces a new predicate "identifier?".
> Isn't this just "symbol?" by a different name? Can someone explain the
> difference?

An identifier is not a symbol.  Symbols, like the one you
get by evaluating 'foo or (string->symbol "foo") are, well,
symbols.  The only operation you can perform on symbols is
symbol->string.  Some implementations extend the operations
on symbols to access/mutate other stuff like a value field
property-lists, unique-name, among others.

Identifiers, on the other hand, are syntax objects (elements
that make up Scheme expressions).  In plain R5RS (and R6RS
sans syntax-case), the programmer has no way of manipulating
the program's identifiers.  You can access the value of a
lexical variable, or you can assign to it, but you have no
way of getting your hand on it in the same way you can hold
symbols, pairs, and other data structures.  You can think of
identifiers as a tuple containing the name of the identifier
(usually represented by a symbol, but that's not strictly
necessary) and its lexical information (marks/substitutions
pair in some implementations).

Operations on identifiers include:
(datum->syntax id datum) which converts the datum to a
   syntax object containing the same lexical information
   as the identifier
(literal-identifier=? id1 id1) which returns true if
   the two identifiers have the same name
(free-identifier=? id1 id2) which returns true if the
   two identifiers refer to the exact same binding (the
   binding may be imported or lexical).
(bound-identifier=? id1 id2) which returns true if
   binding one of the identifiers would also bind the
   other (usually used to perform duplicate identifier
   check for binding forms like let and letrec).

So, symbols and identifiers are not the same thing at
all. They support different operations and each serves
a different purpose.

Aziz,,,

Abdulaziz Ghuloum wrote:
> So, symbols and identifiers are not the same thing at
> all. They support different operations and each serves
> a different purpose.

> Aziz,,,

So I am learning. As you pointed out, without syntax-case and syntax
objects, the difference isn't really exposed to the programmer -
leaving an identifier to be simply a symbol name and that's all. Add in
syntax-case, syntax objects, etc., and now an identifier has to hold
more information than just the symbolic name.

Well, that's why I started this project - to force me to really learn
the "gory details" of how it all works. It's just too much fun.

Brian.

--

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc