Tag: interpreted programming language

ConcatListOfStrings

One of the slow parts about Copper is string handling within Copper itself. In trying to use Copper for handling strings from files, you may discover there is no object type for handling lists of characters. This is different from strings because lists can grow and strings cannot. Thus, the preferred approach is to create a list containing strings of single characters, and this way the list can grow and shrink and be modified. However, it does bring up the problem: How do we get the list back into being a string? After all, it would be annoying to create loops everywhere (e.g. for printing) just to iterate through all the characters.
I decided to create a simple extension function, not part of the engine but one you will definitely want if you work with strings. It’s called StringListConcat, and in Copper, it is str_list_concat(). The function accepts both strings and lists of strings and combines them into a single string as efficiently as feasible on the C++ side.
Simple example:

a = list("Hello" “World”)
print( str_list_concat(a: “Dog") )

Output: HelloWorldDog

Custom Rouge Themes and How to Fix the Ruby Rouge::Theme uninitialized constant problem

After the most recent changes to the Copper programming language and a switch to a newer computer, I decided to finally rebuild the documentation. I have been using the Slate static site generator creating with Ruby on Rails which uses redcarpet and rouge. Sadly, on a new machine, I had to set up everything again. As you may have discovered, rouge, despite its popularity, has really crappy documentation. Ruby itself is crappy in my opinion and I hate working with it, but there has been some nice stuff created with it. Slate is one example. However, after the headache of trying to dig up the documentation, I may switch to using Copper to generate its own documentation. Not a bad idea, no? Anyways, I decided it would be useful to share my tidbits of knowledge with others who will stumble on this problem while creating custom themes for rouge.

Continue reading “Custom Rouge Themes and How to Fix the Ruby Rouge::Theme uninitialized constant problem”

Replacing the Body of an Object Function

Suppose you have an object “a” that you have already instantiated members in.

a.b = 10

Now suppose you need to make the return of “a” equal to 9 so that:

print(a:)

… prints “9”. If you were to assign 9 to “a” directly, you would be giving “a” an entirely new object-function, thereby losing the member “b”. Fortunately, there is a way around the problem. Copper has a built-in function called “share_body” that allows two object-functions to share the same execution body. For example:

c = 9
share_body(c a)

… would allow “a” to have the body of “c”. If “c” gets destroyed from going out of scope, then “a” keeps the body. However, creating a new variable just to make a function body is unnecessary. If we create an ownerless object-function to share its body with “a”, then “a” will become the owner of the body.

share_body({9} a)

The ownerless object-function {9} is instantiated within the function-call parentheses of share_body where it dies but its body lives on. And there you have it, no copies required, no loss of object members.