Adding comments in ulisp gives sometimes strange behaviour


#1

Hi David,

I had my initialization ready for my oled display
It consist of a bunch of commands to make it work
Then I decided to put a comment after every command , just for clarity.
Then I noticed that the compiler didn’t compile the init correctly , I had to add two closing parentheses
to exit the compiler after the upload.
I remember something about comments a long time ago , but can not find it anymore.
What are the do’s and don’ts about adding comments ?
I used something like this :

(defvar *init* '(#xae                  ;display off
                 #xaf                  ;display on
))

Of course the list is much longer.

Kind regards ,
Ronny


#2

Hi Ronny,

It’s in the Language Reference, but you have to look it up “manually”, it’s not mentioned in the summary.


; (semicolon)

Introduces a comment line, which will be ignored. For example:

; Factorial function
(defun f (n) (if (= n 0) 1 (* n (f (- n 1)))))

Because the Arduino Serial Monitor removes line endings uLisp ignores all characters after a semicolon up to the next opening bracket. This imposes a couple of restrictions in the use of comments:

  • Comments should not include an opening bracket.

  • Comments are not valid if they are not followed by an opening bracket; for example:

    (defvar data '(#x01 ; Invalid comment
      #x20))
    

Regards,

rsm


#3

Hi rsm,

Thanks for your reply.
Problem is I don’t use arduino monitor , I’m using gtk-term .
I will look in the language reference .

Regards ,
Ronny


#4

I don’t think it matters. Described uLisp commend threatment is because some popular terminal has strange feature. As I understand it - using different terminal doesn’t change uLisp behaviour. It will still expect ( after a comment.

But I think we need our protagonist to enlighten us as usual :)


#5

Rsm ,

Thanks.
I will post my comments tomorrow as I deleted them , and didn’t care for a backup.
I still wonder what could be wrong.

Ronny


#6

This is the peice of code , that doesn’t compile correctly , without comments it’s ok !

;initialization commands for the oled display

(defvar *init* '(	#xae 					;display off				
			#xd5 #x80				;set display clock
			#xa8 #x3f				;set MUX ratio
			#xd3 #x00				;set display offset to 0
			#x40					;set display start line to 0
			#x8d #x14				;enable charge pump
			#x20 #x00				;set horizontal addressing mode
			#xa6					;set normal display
			#xa4					;display ram contents
			#xa1					;column address 127 is mapped to SEG0
			#xc8					;remapped mode
			#xda #x12				;set COM pins configuration
			#x81 #x8f				;set contrast
			#xd9 #xf1				;set pre-charge period
			#xdb #x40				;set Vcomh deselect level
			#x21 #x00 #x7f			;set column start and end address
			#xaf 					;display on
))

#7

I had to make comments work this way to make it possible to enter programs using the Serial Monitor, which removes line breaks from the input. If you’re not using the Serial Monitor you could change the behaviour by editing this code in nextitem():

  if (ch == ';') {
    while(ch != '(') ch = gfun();
    ch = '(';
  }

to:

  if (ch == ';') {
    while(ch != '\n') ch = gfun();
    ch = '\n';
  }

I haven’t tested it but it should work!
David


#8

Another solution would be for uLisp to support multiline #| … |# comments, which would work under all conditions. However, they’re a bit less convenient to use.


#9

Hi David ,

I changed the code , but this gives errors :

20230> ; scani2c : detect all connected i2c devices on the bus;
Error: undefined: ;

The ; is the first character on the line.

Regards ,
Ronny


#10

David ,
Also strange : bus; while the source is just bus


#11

Correction : this is the source :

; scani2c : detect all connected i2c devices on the bus
; and print the base address in hex


#12

Perhaps best to revert to the previous version and leave the comments out for the time being; I’ll investigate when I get time.


#13

OK.

Thanks anyway.

Regards
Ronny