Author Topic: Closed: Test yourself (for fun). The winner is roy_043  (Read 4560 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Closed: Test yourself (for fun). The winner is roy_043
« Reply #15 on: December 23, 2014, 12:38:05 PM »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

divtiply

  • Guest
Re: Closed: Test yourself (for fun). The winner is roy_043
« Reply #16 on: December 23, 2014, 12:43:00 PM »
I can count to potato.
If you don't like this thread just don't post.

JohnK

  • Administrator
  • Seagull
  • Posts: 10664
Re: Closed: Test yourself (for fun). The winner is roy_043
« Reply #17 on: December 23, 2014, 01:06:43 PM »
The OP posted this challenge:
Name this function:
(lambda (v) (eq 'list (type v)))


The OP said the answer was all about NIL so here is my investigation:

(lambda (v) is only an anonymous function so we can dismiss that
portion of the code. Let's move on to a quick look up of NIL in the
autolisp manual:


NIL
An AutoLISP variable that has not been assigned a value is said to be
nil. This is different from blank, which is considered a character
string, and different from 0, which is a number. So, in addition to
checking a variable for its current value, you can test to determine
if the variable has been assigned a value.

Each variable consumes a small amount of memory, so it is good
programming practice to reuse variable names or set variables to nil
when their values are no longer needed. Setting a variable to nil
releases the memory used to store that variable's value. If you no
longer need the val variable, you can release its value from memory
with the following expression:
command: (setq val nil)
nil

Now that we have at least something on what NIL is we can work our way
through the function (starting from the inside; the lisp interpreter
works from the inside out).

TYPE
http://theswamp.org/~john/avlisp/#type
Items that evaluate to nil (such as unassigned symbols) return nil.

This sentence stuck out at me when reading the help for the function.
Let's move on to EQ and see if my thought thread will pan out.

EQ
http://theswamp.org/~john/avlisp/#eq
Determines whether two expressions are identical

(eq expr1 expr2)

The eq function determines whether expr1 and expr2 are bound to the same object
(by setq, for example).

Arguments

expr1

The expression to be compared.

expr2

The expression to compare with expr1.

Return Values

T if the two expressions are identical, nil otherwise.

So far I am a little concerned as to what the interpreter considers an
`expression'. Let's move on to tackle that vague statement about `it
being all about nil'.

LISTP
http://theswamp.org/~john/avlisp/#listp
is supposed to very that an item is a list so let's give it a whirl on
NIL once.

Command: (listp nil)
T

*red flag #1* I remember from way back when that nil was like an empty
list or something so let me try that.

Command: (listp '())
T

Okay, so we know that NIL is like a empty list. Let's see how TYPE
sees those:

Command: (type nil)
nil

Command: (type '())
nil

*gotcha!*

It appears that (type v) will sterilize the empty-list-nil-type
problem.


EDIT #1 (the OP posted a deeper explanation):
All right.
nil is a list and is an atom both.
vl-consp tests if argument is a _valid_ (not empty) list.
(type nil) -> nil
(listp nil) -> t
(vl-consp nil) - nil

EDIT #2:
> potato
If I didn't understand the challenge does that mean I can't? I mean I don't mind that I'm essentially a newbie again when it comes to lisp but...
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Closed: Test yourself (for fun). The winner is roy_043
« Reply #18 on: December 23, 2014, 01:54:48 PM »

The thread is a success.
It has 6 people talking about nil.

Seriously though, interesting observation.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.