Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - refrainrence

#1
Below the corrected code mentioned first in this thread. I'll try to add a word about nested quote to the topic title. And maybe a word that it's solved. I should check what the forum rules say about it :-) If some expert could add a word to my newest explorations in the land of lisp, i would be grateful :-)

(new Class 'Tag)

(context 'Tag)

(constant 'markup 1)
(constant 'opentag 0)
(constant 'closetag 1)
(constant 'inner 2)
(constant 'v 3)
(define (gen)
  (extend (self 3) (self markup opentag))
  (dolist (el (self inner))
    (:gen el)
    (extend (self 3) "nn" (el Tag:v) "nn"))
  (extend (self 3) (self markup closetag)))

(context MAIN)

(set 't3 (Tag (list "<div>" "</div>") (list) ""))
(set 't2 (Tag (list "<div style="position: absolute">" "</div>") (list t3) ""))
(set 't1 (Tag (list "<div style="position: relative">" "</div>") (list t2) ""))

;(push (t2 Tag:inner) t3)
;(push (t1 Tag:inner) t2)
(:gen t1)
(println (t1 Tag:v))

(exit)
#2
Both dolist and map get the job done:

(new Class 'Tag)

(context Tag)
(define (run)
  (println (self 3))
  ;(dolist (el (self 1)) (:run el)))
  (map (curry :run) (self 1)))
(context MAIN)

(set 't1 (Tag '((Tag () 1 "a") (Tag () 2 "b") (Tag () 3 "c")) 4 "d"))
(:run t1)

(exit)
#3
I tried to simplify this case further using this code:



(new Class 'C)

(context C)

(define (run)
  (println (self 2))
  (dolist (el (self 1) (:run el))))
(context MAIN)

(set 'o1 (C '((C ((C ((C () "sdf")) "zxc")) "qwe")) "asd"))
(:run o1)

(exit)




It seems to run as expected since i removed nested ' (apostrophes or what do u call them..).

My lack of experience in lisp showed up and will get me in trouble again in the future for sure :-)

Looks like it's solved. If anything else unexpected happens i will come back.
#4
newLISP in the real world / FOOP recursive method
March 17, 2014, 12:46:28 PM
Hi,

i'm trying to build a tree of objects to represent html markup. I think of a method that will build a string in this way:

1. write the open tag to a string in (self 2) defined directly in fuction

2. run this method for each object in the list of objects in the field (self 1)

    3. append (self 2) of element in the list to the (self 2) of the object the method is operating on at the moment

4. write the close tag



i get 'list expected' error for both following samples ( second one written to simplify the problem)



(new Class 'Tag)

(context 'Tag)

(constant 'markup 1)
(constant 'opentag 0)
(constant 'closetag 1)
(constant 'inner 2)
(constant 'v 3)
(define (gen)
  (set 's1 "")
  (extend s1 (self markup opentag))
  (dolist (el (self inner))
    (:gen el)
    (extend s1 "nn" (el Tag:v)))
  (extend s1 (self markup closetag))
  (setf (self v) s1))

(context MAIN)

(set 't3 (Tag '("<div>" "</div>") '() ""))
(set 't2 (Tag '("<div style="position: absolute">" "</div>") '(t3) ""))
(set 't1 (Tag '("<div style="position: relative">" "</div>") '(t2) ""))

;(push (t2 Tag:inner) t3)
;(push (t1 Tag:inner) t2)
(:gen t1)
(println (t1 Tag:v))
(println t1)

(exit)





(new Class 'Tag)

(context Tag)
(define (run)
  ;(set 'l1 (self 1))
  ;(println (list? (self 1)) " " (self 3) " " l1)
  (dolist (el (self 1))
    (:run el)
    (println (self 2))))
(context MAIN)

(set 't1 (Tag '((Tag '() 1 "a") (Tag '() 2 "b") (Tag '() 3 "c")) 4 "d"))
(:run t1)

(exit)




I'll try to substitute dolist with map or sth else.
#5
Thanks Ted for support. I insist that Newlisp is a part of my project, and i'm sure it will pay off in some time.

 Meanwhile, creating windows with OpenGL context turned out to be tricky using shared libraries under windows. I'm still not much closer to be an expert in this subject, so not much more to say. Under Linux these stuff just work.

 I also decided to use a game engine. Learning OpenGL takes too much time now. Without the engine i think i would end up writing my own shared libraries in c performing low level routines anyhow. But testing alternative game rulesets should be much easier using Newlisp, right? Below sample.c program from the http://raydium.org/">Raydium Engine rewritten in Newlisp.



(if
  (find ostype '("Win32", "Cygwin"))
  (begin
     (set 'RAYDIUM_LIB "raydium.dll"))
  (= ostype "Linux")
  (begin
    (set 'RAYDIUM_LIB "libraydium.so"))
)

(import RAYDIUM_LIB "raydium_clear_frame")
(import RAYDIUM_LIB "raydium_ode_draw_all")
(import RAYDIUM_LIB "raydium_rendering_finish")
 ;~ (import RAYDIUM_LIB "raydium_init_args")
(import RAYDIUM_LIB "raydium_init_load")
(import RAYDIUM_LIB "raydium_ode_ground_set_name")
(import RAYDIUM_LIB "raydium_callback")
(import RAYDIUM_LIB "raydium_camera_freemove")
(constant 'RAYDIUM_CAMERA_FREEMOVE_NORMAL 1)
(constant 'RAYDIUM_ODE_DRAW_NORMAL 0)

(define (display)
   (raydium_clear_frame)
   (raydium_camera_freemove RAYDIUM_CAMERA_FREEMOVE_NORMAL)
   (raydium_ode_draw_all RAYDIUM_ODE_DRAW_NORMAL)
    (raydium_rendering_finish))

(raydium_clear_frame)
(raydium_init_load "simple.conf")
(raydium_ode_ground_set_name "cocorobix.tri")
(raydium_callback (callback 0 'display))

(exit)



Works right out of the box under win7 AMD 64 and slack14 i386.

 It will take some time till the code would get interesting probably. The game will be in 2.5D environment and should run fine on older hardware.
#6
@Astrobe Thanks for the reply. Rather i will find me another project than continue with the game without newlisp. The goal is to use LISP-like language ( because typing 'for (..) {;;;}' by my own will in the spare time gives me a headache). At least this is what i think atm.



So what happened next on my journey with the game project? I replaced nil symbols/values in the argument list in the glfwCreateWindow call with 0's. This resulted in code running correctly ( from my observation) under slack 14 i386. By the way i couldn't find an example anywhere showing how to pass NULL as an argument of type 'pointer to struct' inside an imported function. Probably seems obvious to experts on c lang, but maybe it is worth to be put in the docs too? The code also worked on win7 AMD 64 after using http://sourceforge.net/projects/dxglwrap/">DirectX OpenGL Wrapper as opengl32.dll replacement. I then came to conclusion, that switching to the 'extended ffi' wouldn't hurt too, if i'm going to avoid unexpexted problems in the future. My code so far:



(if
  (find ostype '("Win32", "Cygwin"))
  (begin
    (set 'GL_LIB "opengl32.dll")
    (set 'GLFW_LIB "glfw3.dll"))
  (= ostype "Linux") ;; not tested
  (begin
    (set 'GL_LIB "libGL.so")
    (set 'GLFW_LIB "libglfw3.so"))
)

(import GLFW_LIB "glfwCreateWindow" "void*" "int" "int" "char*" "void*" "void*")
(import GLFW_LIB "glfwInit" "int")
(import GLFW_LIB "glfwTerminate" "void")
(import GLFW_LIB "glfwMakeContextCurrent" "void" "void*")
(import GLFW_LIB "glfwWindowShouldClose" "int" "void*")
(import GLFW_LIB "glfwSwapBuffers" "void" "void*")
(import GLFW_LIB "glfwPollEvents" "void")
(import GL_LIB "glGetString" "char*" "int")
(constant 'GL_VENDOR 0x1F00)
(constant 'GL_RENDERER 0x1F01)

(if
(= (glfwInit))
(begin
(println "Error: glfwInit failed.")
(exit)))
(set 'window (glfwCreateWindow 640 480 "Hello World" 0 0))
(if
(null? window)
(begin
(println "Error: glfwCreateWindow failed.")
(glfwTerminate)
(exit)))
(glfwMakeContextCurrent window)
(while
(= (glfwWindowShouldClose window))
true
(glfwSwapBuffers window)
(glfwPollEvents)
; (sleep 100)
)
(println (get-string (glGetString (| GL_VENDOR GL_RENDERER))))
(glfwTerminate)
(exit)



From the GLFW docs on glfwCreateWindow function:
Quote
Returns

    The handle of the created window, or NULL if an error occurred.

Is this a correct way to check for error:

(if
   (null? window)
   (begin
   (println "Error: glfwCreateWindow failed.")
   (glfwTerminate)
   (exit)))

?
#7
I only figured out that importing 64 bit dll into 32 bit newlisp won't  work ( at least i hope i'm right about it :-P ) yet.

I gave up on glut to glfw library instead. I tried to translate this sample: http://www.glfw.org/documentation.html">//http://www.glfw.org/documentation.html into newlisp:



(import "glfw3.dll" "glfwCreateWindow")
(import "glfw3.dll" "glfwInit")
(import "glfw3.dll" "glfwTerminate")
(import "glfw3.dll" "glfwMakeContextCurrent")
(import "glfw3.dll" "glfwWindowShouldClose")
(import "glfw3.dll" "glfwSwapBuffers")
(import "glfw3.dll" "glfwPollEvents")

(if
(= (glfwInit))
(begin
(println "Error: glfwInit failed.")
(exit)))
(set 'window (glfwCreateWindow 640 480 "Hello World" nil nil))
(if
(nil? window)
(begin
(println "Error: glfwCreateWindow failed.")
(glfwTerminate)
(exit)))
(glfwMakeContextCurrent window)
(while
(= (int (glfwWindowShouldClose window)))
(glfwSwapBuffers window)
(glfwPollEvents))
(glfwTerminate)
(exit)



It still complains about missing function in opengl32.dll without having a mesa dll inside newlisp installation dir (which should result in using a windows version of opengl32.dll). But the point is even using mesa version of opengl this code hangs and 'program stopped working...' dialog appears. If i comment out the while loop the code exits without error in short time. Anyway it seems like something slightly blinks for a moment while firing the script.



Given the return type of glfwWindowShouldClose is int, is comparing to 0 done correctly in my code?
#8
I want to create a not too sophisticated but a real, playable 3D game in newlisp to run on win7 and linux.

I cannot get past firing up the teapot demo found here: http://www.newlisp.org/syntax.cgi?downloads/OpenGL/opengl-demo-ffi-lsp.txt">//http://www.newlisp.org/syntax.cgi?downloads/OpenGL/opengl-demo-ffi-lsp.txt.


(println (get-string (glGetString (| GL_VENDOR GL_RENDERER))))


gives me output similar to 'Windows Mesa DRI rendering'  on windows 7 while on slack 14 i get desired 'R300 ......' string. I assume this means i cannot have hardware rendering in win7. I think i must have it to develop a real 3D game, not just a proof of concept.



I tried to import glGetString from opengl32.dll shared library inside c:windowssystem32 dir but it returns 'problem loading library in function import...'

Why opengl32.dll from http://www.turtle.dds.nl/gl4newlisp/">http://www.turtle.dds.nl/gl4newlisp/ works, but dll provided by windows doesn't?

I also tried importing glfw3.dll function glfwInit but also ended receiving 'problem loading...' provided this dll file was copied into same dir.



I don't have a knowledge about ffi to even figure out how properly use glfw. I just thought i write an import in newlisp and it would work.



Please help, how to get opengl hardware rendering on windows 7 in newlisp?
#9
Thanks hilti, thanks cormullion for objective-newlisp link, i think i may need circular links and deep nested access. I will try to write some lines using objective-newlisp later. But before that, i'm going to do some FOOP scripting.



I managed to write a possible solution:




(define (Circle:Circle x y radius)
    (list Circle x y radius))

(define (Circle:area)
    (mul (pow (self 3) 2) (acos 0) 2))


(set 'methods '((:area) (:area)))

(set 'mycircle (Circle 1 2 10))

(dolist (x methods) (println "looping: " (eval (append x '(mycircle)))))



output:



(lambda (x y radius) (list Circle x y radius))
(lambda () (mul (pow (self 3) 2) (acos 0) 2))
((: area) (: area))
(Circle 1 2 10)
looping: 314.1592654
looping: 314.1592654
314.1592654


Does it look alright?
#10
Hi there,



i play with newLISP from time to time because writing code in 'real world' languages feels like merry go round. So to avoid a lapse of reason i'm playing atm with my imaginary programming task which goes :



Take list of method names stored in list of strings ( or symbols - i'm an ignorant noob) and invoke them on an object.



What i have now:



(define (Circle:area)
    (mul (pow (self 3) 2) (acos 0) 2))

(set 'method1 '(:area))

(set 'mycircle (Circle 1 2 10))

((nth 0 method1)(nth 1 method1) mycircle)



This is my first post, so it's a good time to thank you people, who are behind newLISP for this outstanding piece of software :-)



I'd like to follow with a few more questions considering FOOP in this same thread if you don't mind. The context of newLISP is main reason for using this language to me, so forgive me i started learning from this point and not the basics. I just can't figure out if context from newLISP works for me or not. I'm trying to build my own approach to OOP paradigm. Based on composition, without inheritance. I want to replace PHP with NewLISP as a foundament.



cheers