/dpt/ - Daily Programming Thread

Previous Thread: What are you working on, Sup Forums?

Other urls found in this thread:

wiki.osdev.org/Main_Page
os.phil-opp.com/
github.com/organix/pijFORTHos
stackoverflow.com/questions/334856/are-there-benefits-of-passing-by-pointer-over-passing-by-reference-in-c
test.com/ID
twitter.com/SFWRedditGifs

Is this supposed to be a bad thing?

Who is this semen demon?

Objects. I'm working on objects.

>OOP

...

I'm about halfway through LYAH and I think I'm falling for the Haskell meme.

I think it's parody.

post code and i'll microprettify it

I understand that, but it's parody done in such a way as to make the language (or at least its users) look bad.

Even McCarthy hated the terms 'cons', 'car' and 'cdr'; he tried to promote 'first' and 'rest' instead.

Why do you keep using this archaic terminology?

Preach it brother

it's sugar

Yeah the latter.

>not "head" and "tail"

I think he was being silly.

can someone choose a haskell anime girl? if not, i will

That's what I use. Note that I didn't advocate 'first' and 'rest', I just criticised 'car', 'cdr' and 'cons'.

Pleb.

Because lists are made from dotted pairs and there is no word in english for first element of a pair and second element. Rest doesn't cut it, because it's always just one (if compound) element.

cons is short for construct, easy to remember, quick to type. You use it a lot so that's why that's important.

so, since we don't have any proper words car and cdr are fine, also their origin is interesting. Another nice property of car and cdr is that they are easily stackable (cadr, cddr, ...) and have same number of characters, so they align well.

Also everybody knows car and cdr, every dialect has them, while some dialects don't have first and rest.

yeah, I know it takes two seconds to define synonims, but thats already too much effort for such a meaningless matter.

>there is no word in english for first element of a pair and second elemen
how about first and second?

first and second makes you expect third and fourth, which is quite fine with lists, but not with pairs. Head and tail is better, but it makes it seem that there is a difference between the elements. car and cdr is quite fine.

also stackability is the main benefit of car and cdr, being able to use (cadar lst) instead of (head (tail (head lst))) helps readability greatly. Negate this point.

>1919x1079

you wut nigger?

you're using a language where everything is fucking lists

of course it doesn't make any sense

in minimal lisp everything is either an atom or a dotted pair. Lists are just a special kind of a dotted pair, in which cdr is a nil (empty list) atom.

in most lisps you also have arrays, hashes, ...

>also stackability is the main benefit of car and cdr, being able to use (cadar lst) instead of (head (tail (head lst))) helps readability greatly. Negate this point.
How about a fucking 'nth' function instead of retarded nesting?

because it wouldn't be the same functionality. and we already have nth in many lisps (for example racket's list-ref). Problem of n-th is that third element of list '(1 2 (3 4)) is '(3 4), while caddr is 3.

stacking cars and cdrs allows you to access any item in the tree, while n-th only lets you browse the main branch.

which scheme has the easiest c interface?

Why does this answer scare the shit out of me?

chicken. easy use of c libraries is it's main selling point and it has both interpreter and fast compiler to c. you can embed c code into it.

TLDR: Lisp lists actually aren't really lists, they are binary trees made from conses. Lists are the special case when repeatedly applying cdr until you get an atom will give you nil (or the empty list in some dialects).

I.e. (a b c d e) is really sugar for (a . (b . (c . (d . (e . nil)))))

But you could also have something like ((a.b) . (c . (d . e))) which is a binary tree, but can not be rewritten in list notation. At best, some dialects might display it as ( (a . b) c d . e).

i use cons to refer to constructing a new list from a head and a tail, but i use head and tail to refer to car and cdr

>everything is btrees
d
u
m
b

binary trees*

>50s (auto)
>tfw

This is an argument of semantics.

>antisemanticism
binary trees and lists are not remotely similar

Binary trees and lists are homomorphic.

Yeah, because it's the semantics which make nth function unable to access any element of binary tree, while allowing car-cdr stackings to do so.

Also these semantics fuck many beginners in the ass, since they forget to check if arg is proper list or dotted pair.

Lists of As: X = 1 + AX
Binary trees of As: X = 1 + AX2

Because Sup Forums hates some Unicode:
X = 1 + AX^2

let s = [round(2**x) | x

You forgot to write "praise hiroyuki"

No, there are many things you can do with cons cells that you cannot do using only lists, if you care about what the computer is actually doing.

cons/car/cdr are more general than just lists. You should think of cons cells as a fundamental building block for data structures much like pointers in C.

What's the difference between a pointer and a reference in sepples?

Or is that like asking what's the difference between a string and a string literal?

>Yeah, because it's the semantics which make nth function unable to access any element of binary tree,
Any tree can be given a sequential numbering so a function nth(tree, x) can always be made to address any node in the tree.

Why don't programmers distinquish Halloween from Christmas?


Because Oct 31 equals Dec 25!

haha, so funny
got it from an autism forum

that joke is so old that i forgot the meaning

oh wait i just remembered
it's not funny

in which case it's easier to know what are you going to get?
(nth 6 '(a . ((b . c) . d))
(cddr '(a . ((b . c) . d))

A pointer is a variable that may contain the address of another variable.

A reference is creating a new name for a variable, and passing the reference around is only passing the name around.

You can reassign a pointer to a different variable, you can't reassign a reference.

>what's the difference between a string and a string literal?
Pretty big difference actually.

A reference is supposed to always refer to a valid object.

XD I will tell this joke to all of my coworkers

Well, value, anyways.

fucked up the parens, add one to each line -.-

Stop lying, NEET.

what's oct mean

octal, you know the base 8

I have a habit of using my mouse to draw out the region I want to screenshot. I think I've only gotten 1920x1080 perfectly once.

oh, funny.i assumed dec meant decrement

Can someone give me good example or some read with good explonation beyond the standard shit about C and C++ pointers and pointers with objects.

How do they work, what to avoid, what is good practice and how / when to use them ?

Ive been writing and learning C++ for 7 months now but besides the general use and small tutorials with pointers I have not used them in anything serious.

And mostly I am doing stuff with OpenCV and CV in general, still no real use for them.

So I wonder, am I doing something wrong ? If I know how to use them, will I spend less time programming, or actually improve the design of my program ? Or even better, optimize it ?

why are there two threads

the other thread is just trap posting

The other was made before the bump limit and never linked as far as I can tell

it linked, fifth post from bottom up approximately

? that's this thread you doofus

She's cute. What anime?

Himegoto

that's the (shitty) joke
31st october is the same as 25th december because octal 31 is the same as decimal 25

Yes, I realize this, but to say that LISP lists aren't really lists is just masturbation.

What's the best resource for OS development?

lisp lists are lists, but they aren't one of primitives and the primitive from which they are implemented, is a dotted pair --> binary tree.

# Prints out a pyramid to the terminal consisting of upper case letters, where each
# row is a palomino of the adjacent letters in the alphabet centered at the letter
# of the current row relative to the given letter.
import string


def get_pyramid(letter, rows):
alphabet = string.ascii_uppercase
start_ind = alphabet.find(letter)
# To only print out as wide a pyramid as the
# bottom line:
if start_ind + rows > len(alphabet) - 1:
bottom_length = 2 * (len(alphabet) - start_ind) - 1
else:
bottom_length = 2 * rows - 1
pyramid_str = ""
curr_row = 0
# We dont want to go outside of the alphabet,
# we dont want to make more rows than requested:
while curr_row < rows and curr_row + start_ind < len(alphabet):
# Get left half of current row:
half_curr_str = alphabet[start_ind: curr_row + start_ind]
mid_letter = alphabet[start_ind + curr_row]
curr_line = half_curr_str + mid_letter + half_curr_str[::-1]
pyramid_str += "{:^{}}".format(curr_line, bottom_length) + "\n"
curr_row += 1
if curr_row < rows:
print("Too many rows requested. Returning maximum possible"
" pyramid.")
return pyramid_str

if __name__ == "__main__":
start_letter = input("What is the start letter?: ")
pyramid_height = int(input("How many rows do you want to print?: "))
pyramid_str = get_pyramid(start_letter, pyramid_height)
print(pyramid_str)


R8

This wiki is pretty cool:
wiki.osdev.org/Main_Page

You have a few different options:
1. use asm only (templeos)
2. use c with some lines of asm to boot everything up (*nix)
3. use some c and then continue with rust (quite some projects)
4. make a minimal forth intepreter in asm or c and write os in it (was very popular in the past and is one of easier approaches).

more resources:
os.phil-opp.com/
github.com/organix/pijFORTHos

Lot's of people recommend tannenbaum books, but they have some problems.

and the only candidates harder to read than lisps are ... all other languages except haskell, but especially perl.

Any native language can be used for OS development. It's just a special case of embedded development...

Hell, there's even academic managed OSs running on top of virtual machines that were built to run on bare metal.

for(size_t l = messages.size() - 1 ;l < (messages.size() - 1) - lines;l--)
{
int output_message = func(messages[l]);
if(output_message)
wprintw(vin,string("" + " " + messages[l].message + "\n").c_str());
wrefresh(vin);
}

How did I fuck this up?

Ment palindrome jesus.

yeah, but these are the usual candidates.
problem with most modern languages is that they expect runtime -- garbage collection, standard libs, ... and you simply don't have this, you have to still provide it.

There was also a significiant minority of lisp oses - google lisp machines. You can't do that with most of modern day lisps, due to afforementioned problems. But a small lisp intepreter is trivial to write in c or even asm.

I don't know user, but I'm not enjoying myself very much.

c++

void passByRef(int *i);

void passByRef2(int &i);


which is correct? i've been taught both but don't understand the difference

Any idea what determines how "portable" an OS would be? Obviously different CPU architectures would require different compiler options and probably some special case code, but beyond that would you need to specifically code support for different motherboards/chipsets/whatever or would the BIOS handle those differences?

stackoverflow.com/questions/334856/are-there-benefits-of-passing-by-pointer-over-passing-by-reference-in-c

First one allows you to reassign i inside the function and you can treat i as an optional value by using null as the invalid value.

Otherwise the only difference is syntactical, second one deson't require address-of and dereference operators.

Personally I prefer the pointer version because it makes it more clear you're passing something 'by reference' at the call site:
passByRef(&someObject); // Immediately upon reading this I know a copy isn't made

passByRef2(someObject); // is it copied or a reference? have to look at function signature
[/cpde]

Most of the c code you are going to write will be portable.

These are 2 things that you have to write in assembler:
1. bootloader (or just use grub, lilo, etc.) or
2. some code for configuring grub, any other bootloader

Any code in asm isn't portable. Another problem for portability are drivers.

If your *nix requires drivers for some hw, your os will need them too. if it doesn't, you are probably safe.

Some advice:
- don't focus on portability too much in the beginning, your first os won't be your best os
- use emulators like qemu
- don't write your own bootloader, seriously, it's one of the hardest parts of os

thanks

>don't write your own bootloader, seriously, it's one of the hardest parts of os
Uh, no. It's not even close to one of the hardest things.
A minimal bootloader is just switching to protected mode and loading the kernel code.

...

hahahhahahhaahahahaa
to be fair
doing string shit in lisp is undesirable
symbols are better

holly fuck, ocaml is unreadable
and they have the Maybe data time, but they're called options?
I bet it doesn't even have classes like haskell does
and no purity too, yuck

the only advantage of ocaml over haskell is speed, and even here haskell is slowly overtaking it.

Option doesn't actually bother me desu, it's just that it's a different convention

>- don't write your own bootloader, seriously, it's one of the hardest parts of os
Not really.
You just need to setup your environment (descriptor tables, paging, protected, long mode, etc) load some bytes from disk. Doesn't require much code at all. I would say getting multitasking up and running is much more challenging.
Especially easy if you want to use UEFI (don't even need any assembler, UEFI can even take care of putting you in long mode with 1:1 paging).
(Of course it can be a complete distraction since it doesn't really have anything to do with the rest of your OS development.)

I'm kinda new to programming and I'm absolutely stumped on a solution. I'm trying to check for duplicates of something in a list to determine uniqueness.

How could I do this?

Hi, could anyone help me understand why I keep receiving this error & a solution to fix it?

Thanks

The naive way is to sort the list and check if two adjacent items are the same.

The O(n) space way is to go through the list and put evrything into a hash table, if you get a collision that's a dup.

naive and slow solution:
for every element in list
remove that element from list
check if element is still member of list

or just sort the list and check adjacents

>for every element in list
>remove that element from list
>check if element is still member of list

foldr foo []
where foo x xs | elem x xs = xs
| otherwise = x:xs

Can someone suggest a way to open a website from C using a variable in the URL?
Like if I want to open
test.com/ID
where "ID" is an int variable.

yes