freenode/lisp - IRC Chatlog
Search
18:29:23
jeosol
Does cl-mop:deep-copy of an object creates a complete new copy even for slots that are class objects?
18:30:11
jeosol
I am trying to create a new fresh object and modify one of the slot objects. Or what is a better way to do this.
18:31:31
jeosol
I have used cl-mop:deep-copy, I changed the inner slot object and when printed, they have the same value, so I am not doing something right
18:36:35
Bike
it looks like it copies values of class slots, but that just means changing the value of the class slot, which is after all shared
18:38:09
jeosol
Bike: I apologize for the lack of clarity. I mean have another object that is a slot in the outer one.
18:42:59
Bike
i mean, deep-copy calls copy-tree, but that won't copy the elements in the tree, just the conses
18:50:33
jeosol
I see. I was able to get it fixed by still performing a separate copy of the slots. I have used this approach (two step copy) in the past to get the objects to be different and not sure if there is a better way.
18:53:38
jeosol
I am trying to do sensitivity analyses by changing some slots (2 or more) in the parent object and can do by a function and submit in parallel
18:54:11
jeosol
Once I change the objects, I use it to create a deck for another black box function (external physics simulator)
18:55:19
jeosol
each one writes a different input deck when evaluated. I could do it sequentially on the same object, but trying to get the results faster by doing parallel calls.
20:05:15
thijso
Ah, ok. Yeah, then you're out of luck. Only way I see is to copy into a newly created hashtable with the correct test, but that is probably quite expensive...
20:10:43
aeth
I think the general expectation is to work with symbols/keywords if possible, where string= hash tables would mostly be for keys for things based on user input... so, yes, it's inconvenient, but not as commonly needed as it is in many other languages
20:11:47
aeth
Depending on what you'd need, you could make a make-hash-table* that defaults to string= (or equal or whatever), or a copy-hash-table... but alexandria has the latter.
20:12:06
pjb
seok17: (defun change-hash-table-test (old new-test) (let ((new (make-hash-table :test new-test :size (hash-table-count old)))) (maphash (lambda (k v) (setf (gethash k new) v)) old) new))
20:12:52
aeth
It looks like alexandria:copy-hash-table takes a keyword argument called test where if it's defined it will change what the test is (and if it isn't, it keeps the old test). So you could turn default hash-tables into #'equal hash tables that will also work on strings
20:14:10
aeth
You could also test for EQUAL or STRING= or EQUALP or STRING-EQUAL being used in the HASH-TABLE-TEST first to save a copy.
20:14:21
pjb
(let ((old (make-hash-table))) (setf (gethash "foo" old) 42 (gethash (copy-seq "foo") old) 1) (hash-table-keys (change-hash-table-test old 'equal))) #| --> ("foo") |#
22:27:09
mrcode_
what's the right way to specialize a method on an array of unsigned-byte vs a string ?
22:29:12
Xach
mrcode_: STRING is a system class, so that will get you a method that acts only on strings. but there isn't anything specific for an unsigned-byte array.
22:30:52
mrcode_
Xach: does this mean it's impossible to specialize a method for a (simple-array character *) vs (simple-array (unsigned-byte 8) *) ?
22:47:39
mrcode_
hmm, I guess a quick followup to that, how does one specialize a method on an array in general ?
22:51:14
pjb
mrcode_: the right way to do that is to define two custom classes, one that wraps the array of unsigned-byte and the other a string, and to specialize on those classes.
22:53:15
pjb
Of course, you can also specialize on the classes returned there, or rather, one of their superclasses, since the result is somewhat implementation dependent or too restrictive: (values (class-name (class-of (make-array 3 :element-type 'unsigned-byte))) (class-name (class-of (make-string 3 :element-type 'character)))) #| --> simple-vector ; simple-base-string |#
22:54:03
pjb
mrcode_: array is definitely a system class, you can specialize on it. (find-class 'array) #| --> #<built-in-class array> |#
22:54:57
pjb
mrcode_: defining wrapping classes would have to be done, assuming you don't want your method to dispatch for arrays of signed-byte or arrays of (unsigned-byte 8), say…
23:11:25
no-defun-allowed
I think the "self" column is how many samples have called that function last, and "total" is how many have that function anywhere on the stack.
23:17:47
no-defun-allowed
But then that would mean my interpreter is in the dispatch loop (as opposed to running some code) 53% of the time, which I don't believe.
23:27:30
no-defun-allowed
Could try that. My opcodes are lambda functions and thus I can't name them to trace, but I'm interested to see if that 53% number is anything near realistic.
23:29:42
no-defun-allowed
Or that could be possible, since the loop does quite a few checks to limit conses and cycles and establishes a restart too.
23:32:27
no-defun-allowed
Yep, it was that restart all along. I guess I will have to split up this loop into a setup part, then a run part, so that it's possible to continue running the interpreter when we raise a signal for some external data.
1:02:28
DrDuck
Can I expect Winston and Horn's code from their 'Lisp' book to compile even though the book was published in '89?
1:09:00
Bike
no, the garbage collector is not standard. also, if you can refer to an object and pass it to such a function, it's not garbage
1:09:02
no-defun-allowed
Well, if there was some function for it, calling it would create a reference to that object, so no.
1:09:31
no-defun-allowed
But (trivial-garbage:gc :full t) will do a full garbage collection (if you load the trivial-garbage system).
1:12:41
no-defun-allowed
It would be terribly inefficient to garbage collect only one object, when a significant proportion of the heap is scanned.
1:14:39
DrDuck
i want to force the garbage collector to clear up some memory explicitly when i tell it to
1:15:14
Bike
well, as ddefun said, the implementation usually has a hook to run the collector manually
1:16:27
Bike
in a garbage collected system memory is not really a concern directly, so you should only need to worry about it if you need to tune performance or the like
1:16:59
Bike
especially, you can't do something like (free x) (print x) like you can in C (i mean, it's invalid, but you can write it)
1:51:35
p_l
DrDuck: with automatic memory management, usually the only thing you can do is to explicitly trigger the GC, but not tell it to collect something. There are ways to handle that, though, like object caches and sometimes there are ways to get manual memory control
1:53:20
p_l
yeah, dynamic-extent hints to compiler that the specified binding will have values that live only within scope
1:54:23
p_l
analogue: "industry" is notoriously bad guideline in Lisp case. Most visible popular stuff? Clojure and Racket. Hidden in weird places doing important work? Common Lisp and helluva lot of Scheme. With occassional throwback to pre-ZetaLisp days
1:55:39
p_l
and by helluva lot of scheme I mean "significant portion of PS3 and PS4 consoles got to run a heavily Scheme-d software"
1:56:24
no-defun-allowed
Did you know...tinyscheme is used in macOS access control of some sort I forgot the name of?
1:56:46
p_l
analogue: the general guideline is that if you want to use Lisp (any lisp), take a task where nobody except you cares about language choice
1:57:24
p_l
that's surprisingly common in enterprise software, where they pay you to solve a problem, and language is last thing they are going to inquire on so long as it works on their systems
1:58:18
p_l
analogue: drew doesn't show up here much anymore, but he talked about earning money mainly by making intranet web apps for various companies
1:58:36
p_l
the companies didn't ask him to program in specific language, they asked him to solve a problem
1:59:03
p_l
and sometimes you might even end up building a new language to fit their requirements, where Lisp makes a lot of things easier :)
2:00:20
p_l
analogue: one use case you might have is to introduce dynamic programming by end user to such a codebase
2:01:30
p_l
the aforementioned blockly use case? we pitched to client that they would be able to change processing equations/rules without having a java & PL/SQL expert come and recompile the program
2:05:03
p_l
well, with exception of Allegro's "modern mode" (lowercase, case-preserving), all important implementations comply with ANSI CL standard
2:05:09
no-defun-allowed
The differences between those implementations include compilers and extensions (like exposing GC functions, FFI, threads, etc)
2:05:46
p_l
LW for example has pretty nice GUI library and AFAIK splendid delivery options (plus stuff like WHO-CALLS)
2:06:24
analogue
Scheme appeals to me the most I think, would you say it is much to transition between the languages?
2:07:27
p_l
analogue: significant differences, IMO. CL has non-hygienic macros and doesn't care that much about text representation of code. ANSI CL is also much bigger standard by itself and thus a lot of things that are "every implementation is different" in Scheme are boringly standard in CL
2:07:51
p_l
ck_: iirc, SLIME's doesn't support querying who call's function at point on all implementations
2:08:52
minion
analogue: direct your attention towards pcl: pcl-book: "Practical Common Lisp", an introduction to Common Lisp by Peter Seibel, available at http://www.gigamonkeys.com/book/ and in dead-tree form from Apress (as of 11 April 2005).
2:08:56
ck_
p_l: sure. I just wondered why you singled out the lispworks functionality -- perhaps because it works slightly differently or better.
2:09:01
minion
analogue: paip: Paradigms of Artificial Intelligence Programming. More about Common Lisp than Artificial Intelligence. Now freely available at https://github.com/norvig/paip-lisp
2:09:24
p_l
analogue: I don't have much on scheme, but "How to Design Programs" might be of interest
2:09:50
p_l
and of course the classic (light on Scheme, heavy on Computer Science) "Structure and Interpretation of Computer Programs"